home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / language / prlogtxt.arc / PROLOG.DOC next >
Text File  |  1988-07-24  |  106KB  |  2,687 lines

  1.  
  2. TOY Prolog ST V3.3              1                   Documentation
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. TTTTTT  OOOO  YY  YY    PPPPP  RRRRR   OOOO  LL      OOOO   GGGGG
  17.   TT   OO  OO YY  YY    PP  PP RR  RR OO  OO LL     OO  OO GG
  18.   TT   OO  OO YY  YY    PP  PP RR  RR OO  OO LL     OO  OO GG
  19.   TT   OO  OO  YYYY     PPPPP  RRRRR  OO  OO LL     OO  OO GG
  20.   TT   OO  OO   YY      PP     RR RR  OO  OO LL     OO  OO GG GGG
  21.   TT   OO  OO   YY      PP     RR  RR OO  OO LL     OO  OO GG  GG
  22.   TT    OOOO    YY      PP     RR  RR  OOOO  LLLLLL  OOOO   GGGGG
  23.  
  24.  
  25.  
  26.  
  27.  
  28.                     TOY Prolog ST, Version 3
  29.                     ========================
  30.  
  31.                              Manual
  32.                              ======
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.    Translated from the German documentation by Martin Willson
  49.  
  50.        for the ST Club, 9 Sutton Place, 49 Stoney Street
  51.  
  52.                       Nottingham, NG1 1LX, UK
  53.  
  54.  
  55.                          September 1988
  56.  
  57. TOY Prolog ST                   2                        Contents
  58.  
  59.  
  60.  
  61.  
  62.                             CONTENTS
  63.  
  64. 1    Copyrights   3
  65. 2    Syntax and User Interface   3
  66.   2.1  The Syntax of TOY Prolog   3
  67.   2.2  The User Interface   7
  68. 3    System Functions and Predefined Predicates   8
  69.   3.1  General   8
  70.   3.2  Description of the system functions and predefined
  71.        predicates   9
  72.     3.2.1  General predicates   10
  73.     3.2.2  Arithmetic with integer numbers   10
  74.     3.2.3  Comparison of numbers or names   11
  75.     3.2.4  Comparison of terms   12
  76.     3.2.5  Input and Output   13
  77.       3.2.5.1  Data streams   13
  78.       3.2.5.2  Switching input/output streams   14
  79.       3.2.5.3  Input aids   16
  80.       3.2.5.4  Input/output of terms; operators   17
  81.       3.2.5.5  Single characters   19
  82.       3.2.5.6  Input/output of single characters   20
  83.     3.2.6  Type testing   21
  84.     3.2.7  Access to the term structure   22
  85.     3.2.8  Access to predicates in the data bank   24
  86.     3.2.9  Control of the course of the program   27
  87.     3.2.10  Aids for the testing of programs   29
  88.     3.2.11  Working on grammatical rules   30
  89.     3.2.12  Miscellaneous functions   30
  90.   3.3  The GEM Functions   32
  91.     3.3.1  Control functions   32
  92.     3.3.2  Graphic output   32
  93.     3.3.3  Attribute functions   33
  94.     3.3.4  Functions for mouse control   35
  95.     3.3.5  Display of an alert message   36
  96.   3.4  Names of the system functions   36
  97. 4    The Auxiliary Programs   37
  98.   4.1  The translator for the User Interface   37
  99.   4.2  The Editor   38
  100.   4.3  The Program Structure Analyzer   39
  101. 5    The Demonstration Programs   40
  102.   5.1  ALPHA   40
  103.   5.2  TOYSEQUEL (relational database)   41
  104.   5.3  Noughts and Crosses   42
  105.  
  106. APPENDICES
  107. A1   Construction of the Interpreter   43
  108. A2   Syntax of the Inner Interpreter   44
  109. A3   The System File   46
  110. A4   Implementation of the User Interface   47
  111. A5   Future Developments   48
  112.  
  113. TOY Prolog ST                   3             Copyrights - Syntax
  114.  
  115.  
  116.  
  117.  
  118. 1. COPYRIGHTS
  119.    ----------
  120.  
  121. The program is based on an implementation of Prolog published  by 
  122. Feliks  Kluzniak and Stanislaw Szpakowicz in their  book  "Prolog 
  123. for Programmers" (Academic Press, London, 1985).
  124.  
  125. The rights for the Atari version lie with Jens Kilian, Bensheim.
  126.  
  127. The  program  is  released  for  public  distribution  under  the 
  128. condition that none of the notices on the existing copyrights  in 
  129. the  various files is removed or altered,  however it may not  be 
  130. sold for profit.
  131.  
  132. This  file  is a translation of the German documentation  and  is 
  133. copyright © Martin Willson 1988 for the translation.  It likewise 
  134. may not be sold for profit.
  135.  
  136. Atari, 520 ST and TOS are trademarks of the Atari Corporation.
  137.  
  138. GEM is a trademark of Digital Research, Inc.
  139.  
  140.  
  141. 2. SYNTAX AND USER INTERFACE
  142.    -------------------------
  143.  
  144. The dialect used is very similar to the dialect Prolog-10 used in 
  145. "Programming  in Prolog" (Clocksin  &  Mellish,  Springer-Verlag, 
  146. Berlin & Heidelberg 1981). Some of the differences will be stated 
  147. further on.
  148.  
  149. 2.1. The Syntax of TOY Prolog
  150.      ------------------------
  151. The notation used is BNF.  The lower case words and the following 
  152. syntax description symbols are non-terminal symbols (i.e.  do not 
  153. appear in actual programs).
  154.      ::-       means 'is defined as', 'consists of'
  155.       |        separates alternatives
  156.     { s }      means that the symbol-sequence s  can be  repeated
  157.                as often as required (or not at all).
  158.      ***       indicates a comment.
  159.  
  160. It is assumed that the normal operator declarations are in force. 
  161.  
  162. clause              ::= definition | grammatical_rule | directive
  163. definition          ::= rule | fact
  164. rule                ::= head :- body
  165. fact                ::= head
  166.      *** The principal functor of head is not :- / 2
  167. head                ::= functor_term
  168. body                ::= alternative_body { ; alternative_body }
  169. alternative_body    ::= call { , call }
  170.  
  171. TOY Prolog ST                   4                          Syntax
  172.  
  173.  
  174. call                ::= functor_term | variable | ( body )
  175. functor_term        ::= term
  176.      *** Not a variable and not an integer; a formal definition 
  177.      *** would be quite costly
  178. grammatical_rule    ::= lefthand_side --> righthand_side
  179. lefthand_side       ::= non_terminal context | non_terminal
  180. non_terminal        ::= functor_term
  181. context             ::= terminal_symbol
  182. righthand_side      ::= alternatives
  183. alternatives        ::= alternative { ; alternative }
  184. alternative         ::= rule_element { , rule_element }
  185. rule_element        ::= non_terminal | terminal_symbol |
  186.                         condition | ! | ( alternatives )
  187. terminal_symbol     ::= list | character_string
  188.      *** Only 'closed' lists are allowed
  189. condition           ::= bracket_term
  190. directive           ::= command | query
  191. command             ::= :- body
  192. query               ::= body
  193.      *** The principal functor of body is not :- / 1
  194.  
  195. term                ::= term1200
  196. termN               ::= opfx,N termN-1 | opfy,N termN |
  197.                         termN-1 opxf,N | termN opyf,N |
  198.                         termN-1 opxfx,N termN-1 |
  199.                         termN-1 opxfy,N termN   |
  200.                         termN   opyfx,N termN-1 |
  201.                         termN   opyfy,N termN   | termN-1
  202.      *** 1 ≤ N ≤ 1200; opT,N is an operator of type T and
  203.      *** precedence N; termN can be called 'term of precedence N'
  204. term0               ::= variable | integer | character_string |
  205.                         list | non_operator | 
  206.                         non_operator ( term { , term } ) |
  207.                         ( term ) | bracket_term
  208. bracket_term        ::= { term }
  209. non_operator        ::= functor
  210. opT,N               ::= functor
  211.      *** T ∈ { fx, fy, xf, yf, xfx, xfy, yfx, yfy }, 1 ≤ N ≤ 1200
  212.      *** see also remark 1
  213. list                ::= [] | [ term999 { , term999 } ] |
  214.                         [ term999 { , term999 } | term ]
  215.      *** Terms of precedence 999 can be linked by commas without
  216.      *** brackets ( , / 2 has precedence 1000)
  217. functor             ::= word | q_name | symbol | solo_char
  218. word                ::= word_initial { alphanumeric }
  219. word_initial        ::= small_letter
  220. alphanumeric        ::= small_letter | capital_letter | digit | _
  221. q_name              ::= ' { q_character } '
  222. q_character         ::= '' | not_'
  223.      *** not_' is any character other than '
  224. symbol              ::= symbol_char { symbol_char }
  225. variable            ::= variable_initial { alphanum }
  226. variable_initial    ::= capital_letter | _
  227. integer             ::= - digit { digit } | digit { digit }
  228.  
  229. TOY Prolog ST                   5                          Syntax
  230.  
  231.  
  232. character_string    ::= " { string_char } "
  233.      *** In TOY a character_string means a list of the names of
  234.      *** the characters, in Prolog-10 a list of their ASCII-codes
  235. string_char         ::= "" | not_"
  236.      *** not_" is any character other than "
  237. small_letter        ::= a | b | c | d | e | f | g | h | i |
  238.                         j | k | l | m | n | o | p | q | r |
  239.                         s | t | u | v | w | x | y | z | ü |
  240.                         é | â | ä | à | å | ç | ê | ë | è |
  241.                         ï | î | ì | æ | ô | ö | ò | û | ù |
  242.                         ÿ | ß | ƒ | á | í | ó | ú | ñ | ª |
  243.                         º | ã | õ | ø | œ | ij
  244. capital_letter      ::= A | B | C | D | E | F | G | H | I |
  245.                         J | K | L | M | N | O | P | Q | R |
  246.                         S | T | U | V | W | X | Y | Z | Ç |
  247.                         Ä | Å | É | Æ | Ö | Ü | Ñ | Ø | Œ |
  248.                         À | Ã | Õ | IJ
  249. digit               ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  250. symbol_char         ::= # | $ | & | * | + | - | . | / | : |
  251.                         < | = | > | ? | @ | \ | ^ | ' | ~ |
  252.                          | ¢ | £ | ¥ | ¿ | ⌐ | ¬ | ¡ | « |
  253.                         » | § | ∧ | ∞ | ≡ | ± | ≥ | ≤ | ÷ |
  254.                         ≈ | ¯
  255.      *** An isolated dot, followed by a space,
  256.      *** is not a symbol_char but a full_stop.
  257. solo_char           ::= , | ; | !
  258. character_group     ::= functor | variable | integer |
  259.                         character_string | bracket_or_slash
  260.      *** Character_groups are used in Remark 6, see below.
  261. bracket_or_slash    ::= ( | ) | [ | ] | { | } | |
  262. comment             ::= % { not_end_of_line } end_of_line
  263.      *** end_of_line is a character that indicates the end of a
  264.      *** line, not_end_of_line is any other character.
  265.      *** TOY Prolog converts all end_of_lines into single CRs.
  266. space               ::= { control_char }
  267.      *** control_char is 'SPACE' or 'TAB' or end_of_line or
  268.      *** any unprintable character (ASCII-Code < 32).
  269. full_stop           ::= . control_char
  270.  
  271. Remarks
  272. ~~~~~~~
  273. (1)  Mixed operators are not included in the description, but the 
  274.      rules for them all have the same form, e.g.
  275.  
  276.      termN               ::= op[xfy,fx],N termN-1
  277.  
  278.      (There are 11 additional rules for mixed operators.)
  279.  
  280.      In  TOY  Prolog a mixed operator can have at  the  most  one 
  281.      unary and one binary type, both with the same precedence.
  282.  
  283. (2)  There   are   many  ambiguous  combinations   of   connected 
  284.      operators, which are not included in this description.
  285.  
  286.  
  287. TOY Prolog ST                   6                          Syntax
  288.  
  289.  
  290. (3)  Not  all  functors  (e.g.   names  in  apostrophes)  can  be 
  291.      declared as operators.
  292.  
  293. (4)  In  the  description of the body we have been able  to  omit 
  294.      separate  consideration  of , / 2 and  ; / 2,  as  both  are 
  295.      normally declared as infix-operators. The rule
  296.  
  297.           body ::= functor_term
  298.  
  299.      has however disguised the structure of a body that occurs as 
  300.      a rule.
  301.  
  302. (5)  The syntax for directives (commands and queries) is oriented 
  303.      towards the user interface employed in TOY Prolog.
  304.  
  305. (6)  Comments  and spaces can be inserted as desired  before  and 
  306.      after character_groups,  but not inside a character_group. A 
  307.      comment extends only up to the next end_of_line.
  308.  
  309. (7)  Between  a minus sign that must be treated as a functor  and 
  310.      an  unsigned  integer there must be a space.  A  minus  sign 
  311.      directly  preceding a  numeral sequence will be regarded  as 
  312.      its sign.
  313.  
  314. (8)  An entered term must be closed with a full_stop (outside  an 
  315.      apostrophised name, a character_string or a comment).
  316.  
  317. (9)  TOY  Prolog  uses  a simple  unification  algorithm  without 
  318.      'occurrence check'.  By this means, for example, the terms X 
  319.      and  f(X)  can  be unified.  In  the  process  there  result 
  320.      cyclical data structures,  which by careless programming can 
  321.      lead  the interpreter into an endless loop during output  or 
  322.      unification. Thus care is needed with such structures.
  323.  
  324. TOY Prolog ST                   7                  User Interface
  325.  
  326.  
  327.  
  328.  
  329. 2.2. The User Interface
  330.      ------------------
  331. The user interface of TOY Prolog is written in Prolog itself.  An 
  332. intermediate code is used,  which shows only slight  restrictions 
  333. compared with the complete syntax,  but can be translated  easily 
  334. into the code used by the inner interpreter. For details on this, 
  335. see the appendices.
  336.  
  337. The inner interpreter calls the predicate ear / 0,  as soon as it 
  338. has  to read from the 'user' input stream.  This predicate  calls 
  339. the main loop of the outer interpreter; its name is loop / 0.
  340.      In the loop the user is asked by the prompt
  341.           ?-
  342. to enter a term, which after that is executed as follows:
  343.  
  344. (1)  Variables or incorrect terms are ignored.
  345. (2)  Numbers generate an error message.
  346. (3)  Terms  of  the  form "head :- body" or  "LHS  -->  RHS"  are 
  347.      adopted into the data bank as rules (grammatical_rules  with 
  348.      '-->' will be translated beforehand).
  349. (4)  Terms  of  the form ":- body" are regarded as  commands  and 
  350.      executed deterministically.
  351. (5)  A list is regarded as a list of filenames.  For analysis  of 
  352.      the list, the predicate 'consultall' will be called.
  353. (6)  All other terms are handled as queries:  an attempt is  made 
  354.      to satisfy the goal described. If it succeeds, the resulting 
  355.      variable instantiations will be printed out,  and the inter-
  356.      preter  will  wait  for the input of  a  character.  If  the 
  357.      character is ';',  it will be attempted to satisfy the query 
  358.      again.
  359.           If  the  query contains no  variables,  'yes'  will  be 
  360.      output on success; if it fails, 'no' is printed out.
  361.  
  362. When the predicate 'stop' is called, the program is interrupted.
  363.  
  364. TOY Prolog ST                   8  Builtin functions & predicates
  365.  
  366.  
  367.  
  368.  
  369. 3. SYSTEM FUNCTIONS AND PREDEFINED PREDICATES
  370.    ------------------------------------------
  371.  
  372. 3.1. General
  373.      -------
  374. System functions are functions that are implemented in the actual 
  375. (inner) interpreter;  predefined predicates are written in Prolog 
  376. and  are read after the start of the interpreter from the  system 
  377. file 'SYSFILE.TOY' (see Appendix A3).
  378.  
  379. The basic functions of Prolog-10 are covered by these two groups. 
  380. In  the  Atari  version,  many additional  system  functions  are 
  381. implemented,  which enable access to the special features of  the 
  382. ST (GEM graphics routines and realtime clock).
  383.  
  384. A  system function can produce three different  results:  it  can 
  385. fail,  succeed,  or produce a system error.  If a system function 
  386. succeeds, side-effects usually occur (e.g. output functions).
  387.  
  388. An  error occurring can have the consequence that the attempt  to 
  389. satisfy  the  current goal is entirely broken off;  it  can  even 
  390. (through  a  memory overflow) go as far as  stopping  the  inter-
  391. preter.  Such a serious error is announced by the message  "fatal 
  392. error : ...". After such an error the interpreter starts indepen-
  393. dently the predicate ear / 0, if it is not reading in a file just 
  394. then.  In the event of an error while opening or closing a  file, 
  395. input and output are diverted beforehand back to the keyboard  or 
  396. screen.
  397.  
  398. Normally,  however,  an error is provoked by other circumstances, 
  399. e.g.  by an incorrect parameter in the call of a system function. 
  400. In this case, satisfaction of the current goal is not stopped; it 
  401. is  continued as if the term provoking the error were a  call  of 
  402. the predicate error / 1.  The argument of error(...) is here  the 
  403. incorrect call itself.
  404.        error / 1 is written in Prolog and is in the system  file; 
  405. the  user can write his/her own error  routines.  error(...)  can 
  406. also  be called explicitly.  In the existing version  error(Call) 
  407. prints out a message of the form "System call error:  Call"  when 
  408. the principal functor of Call denotes a system  function,  other-
  409. wise simply "Error : Call". After printing out, error / 1 fails.
  410.  
  411. TOY Prolog ST                   9  Builtin functions & predicates
  412.  
  413.  
  414.  
  415.  
  416. 3.2. Description of the system functions & predefined predicates
  417.      -----------------------------------------------------------
  418. Remark:  In the following descriptions,  statements will be  made 
  419. ~~~~~~   such  as "Predicate tries to unify two terms," when  the 
  420. predicate  fails or succeeds depending on the result of  unifica-
  421. tion. The terms are unified after success.
  422.      "Predicate  tests  a  condition"  means  that  it  fails  or 
  423. succeeds depending on the result of the condition.
  424.  
  425. Parameters will be denoted in the following descriptions as:
  426.  
  427.      TERM      any term
  428.      INTEGER   an integer-number
  429.      VAR       a variable
  430.      VARINT    an integer-number or a variable
  431.      F_TERM    a term  with functor and zero or more arguments
  432.      CALL      see F_TERM (but in the sense of a goal to be
  433.                satisfied)
  434.      ATOM      a functor without arguments
  435.      NAME      see ATOM (but the function considered refers to
  436.                the printable name of the functor)
  437.      CHAR      a NAME consisting of a single character
  438.      FILENAME  the name of a standard input/output stream (see
  439.                the functions see/tell etc.), or a specification
  440.                for a TOS disk file, e.g.
  441.                'B:\FOLDER.1\PROLOG\DATA.PRO'
  442.      CALL_LIST a (possibly empty) list of CALLs
  443.      CHAR_LIST a (possibly empty) list of CHARs
  444.      NUM_LIST  a CHAR_LIST of numeral characters
  445.  
  446. The  parameters  of  the predicate being  described  are  denoted 
  447. PAR_1, PAR_2, etc.
  448.  
  449. In TOY Prolog there exist predefined operators, of which some are 
  450. the  names of predicates.  There is a list in the description  of 
  451. op / 3 in section 3.2.5.4.
  452.  
  453. TOY Prolog ST                  10              General predicates
  454.  
  455.  
  456.  
  457.  
  458. 3.2.1. General predicates
  459.        ------------------
  460. true
  461.                always succeeds
  462.  
  463. fail
  464.                always fails
  465.  
  466. not CALL
  467.                succeeds whenever CALL fails
  468.  
  469. CALL, CALL
  470.                succeeds whenever both parameters can succeed
  471.  
  472. CALL; CALL
  473.                succeeds  whenever  one  of  the  parameters   can 
  474.                succeed
  475.  
  476. check( CALL )
  477.                succeeds whenever the parameter can  succeed,  but 
  478.                does not instantiate any variables
  479.  
  480. side_effects( CALL )
  481.                equivalent to check(CALL); should be used so as to 
  482.                emphasize  that  the  side-effects  of  CALL   are 
  483.                important
  484.  
  485. once( CALL )
  486.                tries to satisfy CALL deterministically (just once)
  487.  
  488.  
  489. 3.2.2. Arithmetic with integer numbers
  490.        -------------------------------
  491. sum( INTEGER, INTEGER, INTEGER )
  492.                succeeds whenever PAR_1+PAR_2 = PAR_3.
  493.  
  494. sum( INTEGER, INTEGER, VAR )
  495.                succeeds  after unifying PAR_3  with the value  of 
  496.                PAR_1+PAR_2.
  497.  
  498. sum( INTEGER, VAR, INTEGER )
  499.                succeeds  after unifying PAR_2 with the  value  of 
  500.                PAR_3-PAR_1.
  501.  
  502. sum( VAR, INTEGER, INTEGER )
  503.                succeeds  after unifying PAR_1 with the  value  of 
  504.                PAR_3-PAR_2.
  505.  
  506. prod( INTEGER, INTEGER, INTEGER, INTEGER )
  507.                succeeds whenever PAR_1*PAR_2+PAR_3 = PAR_4.
  508.  
  509.  
  510. TOY Prolog ST                  11              Integer arithmetic
  511.  
  512.  
  513. prod( INTEGER, INTEGER, INTEGER, VAR )
  514.                succeeds  after unifying PAR_4 with the  value  of 
  515.                PAR_1*PAR_2+PAR_3.
  516.  
  517. prod( INTEGER, INTEGER, VAR, INTEGER )
  518.                succeeds  after unifying PAR_3 with the  value  of 
  519.                PAR_4-PAR_1*PAR_2.
  520.  
  521. prod( INTEGER, VAR, VAR, INTEGER )
  522.                succeeds  after unifying PAR_2 with the  value  of 
  523.                PAR_4 div PAR_1  and  PAR_3  with  the  value   of 
  524.                PAR_4 mod PAR_1.
  525.  
  526. prod( VAR, INTEGER, VAR, INTEGER )
  527.                as the previous case,  but PAR_1 and PAR_2  inter-
  528.                changed.
  529.  
  530. prod( INTEGER, VAR, INTEGER, INTEGER )
  531.                fails when (PAR_4-PAR_3) mod PAR_1 is not equal to 
  532.                0; otherwise it succeeds after unifying PAR_2 with 
  533.                the value of (PAR_4-PAR_3) div PAR_1.
  534.  
  535. prod( VAR, INTEGER, INTEGER, INTEGER )
  536.                as the previous case,  but PAR_1 and PAR_2  inter-
  537.                changed.
  538.  
  539.  
  540. TERM is TERM
  541.                It is assumed that PAR_2 is an arithmetic  expres-
  542.                sion composed of INTEGERs and the standard  opera-
  543.                tors +,  - (either binary or unary), *, / and mod; 
  544.                if  not,  the predicate fails (a system error  can 
  545.                also occur, if PAR_2 contains free variables).
  546.                     If PAR_2 is an expression,  its value is com-
  547.                puted and it is attempted to unify PAR_1 with it.
  548.                     is  can  also  compute a  list  of  the  form 
  549.                [ INTEGER ]  as the value of  this  integer-number 
  550.                (in accordance with the conventions of Prolog-10).
  551.                     is  is used by other predicates  that  regard 
  552.                their   arguments   as   expressions,   e.g.   the 
  553.                following.
  554.  
  555.  
  556. 3.2.3. Comparison of numbers or names
  557.        ------------------------------
  558. less( INTEGER, INTEGER )
  559.                succeeds when PAR_1 < PAR_2.
  560.  
  561. TERM =:= TERM  ( =:= )
  562.                succeeds  when  PAR_1  and  PAR_2  are  arithmetic 
  563.                expressions that have the same value.
  564.  
  565.  
  566. TOY Prolog ST                  12            Comparison operators
  567.  
  568.  
  569. TERM =\= TERM  ( =\= )
  570.                as  =:=,   but  checks  whether  the  values   are 
  571.                different.
  572.  
  573. TERM < TERM    ( < )
  574.                as =:=,  but checks whether the value of PAR_1  is 
  575.                less than the value of PAR_2.
  576.  
  577. TERM =< TERM   ( =< )
  578.                as <, but checks for "less than or equal".
  579.  
  580. TERM > TERM    ( > )
  581.                as <, but checks for "greater than".
  582.  
  583. TERM >= TERM   ( >= )
  584.                as <, but checks for "greater than or equal".
  585.  
  586.  
  587. NAME @< NAME   ( @< )
  588.                succeeds whenever PAR_1 comes before PAR_2 in  the 
  589.                lexicographic order defined by the extended  ASCII 
  590.                character set of the Atari ST.
  591.  
  592. NAME @=< NAME  ( @=< )
  593.                as @<, but checks for "less than or equal".
  594.  
  595. NAME @> NAME   ( @> )
  596.                as @<, but checks for "greater than".
  597.  
  598. NAME @>= NAME  ( @>= )
  599.                as @<, but checks for "greater than or equal".
  600.  
  601.  
  602. 3.2.4. Comparison of terms
  603.        -------------------
  604. TERM = TERM    ( = )
  605.                attempts to unify PAR_1 and PAR_2.
  606.  
  607. eqvar(VAR, VAR)
  608.                succeeds when PAR_1 and PAR_2 are two instances of 
  609.                the same, non-anonymous variable.
  610.  
  611. TERM == TERM   ( == )
  612.                succeeds when PAR_1 and PAR_2 are two instances of 
  613.                the same term.
  614.  
  615. TERM \== TERM  ( \== )
  616.                succeeds   when  PAR_1  and  PAR_2  are  not   two 
  617.                instances of the same term.
  618.  
  619. TOY Prolog ST                  13                    Data streams
  620.  
  621.  
  622.  
  623.  
  624. 3.2.5. Input and Output
  625.        ----------------
  626. 3.2.5.1. Data streams
  627.          ------------
  628. Input  and output in TOY Prolog ST are  data-stream  oriented.  A 
  629. data  stream is (from the user's point of view) the name  or  the 
  630. complete specification of a disk file,  or the predefined name of 
  631. a special input or output device.
  632.  
  633. A disk file can be accessed for reading and writing,  provided it 
  634. is not protected  by the operating system against overwriting and 
  635. is  not on a write-protected disk.  Names of file streams can  be 
  636. for example:
  637.           editor         (one of the auxiliary programs)
  638.           'sysfile.toy'  (the system file)
  639.           'b:\folder.1\data'  (a file named 'data' on a  disk  in 
  640.                          drive B in folder 'folder.1')
  641. Either upper or lower case can be used for file streams.
  642.      A file stream can be opened only in one direction, read-only 
  643. or  write-only.  Opening  a  file stream  several  times  in  the 
  644. same direction has no effect.
  645.  
  646. The predefined data streams are available for communicating  with 
  647. other devices or components of the computer.  They cannot  always 
  648. be accessed for reading and writing, but a predefined data stream 
  649. for which read and write access are allowed can be opened in both 
  650. directions at the same time.
  651.      The predefined data streams and the types of access  allowed 
  652. are tabulated below.  Their names can be written in either  upper 
  653. or lower case (don't forget the apostrophes in upper case.)
  654.  
  655.        Name    |      Read access       |     Write access
  656.    ------------|------------------------|---------------------
  657.       user     | standard user input    | standard user output
  658.                | (keyboard, buffered)   | (screen)
  659.                |                        |
  660.       keybd    | user input             | output to the
  661.                | (keyboard, single char)| keyboard controller
  662.                |                        |
  663.       modem    | read RS232 interface   | write RS232
  664.                |                        |
  665.       midi     | read MIDI interface    | write MIDI
  666.                |                        |
  667.       printer  | not allowed !          | Centronics interface
  668.    ------------+------------------------+---------------------
  669.  
  670. TOY Prolog ST                  14           Switching i/o streams
  671.  
  672.  
  673.  
  674.  
  675. 3.2.5.2. Switching input/output streams
  676.          ------------------------------
  677. Up to 16 file streams can be open at the same time.
  678.  
  679. see( FILENAME )
  680.                the  given data stream becomes the  current  input 
  681.                stream;  if  it refers to a file not  yet  opened, 
  682.                this is opened for reading.
  683.  
  684. seeing( TERM )
  685.                attempts  to unify the parameter with the  current 
  686.                input stream.
  687.  
  688. seen
  689.                If  the  current input stream is  a  file,  it  is 
  690.                closed.  The predefined data stream 'user' becomes 
  691.                the current input stream.
  692.  
  693. tell( FILENAME )
  694.                the  given data stream becomes the current  output 
  695.                stream;  if  it refers to a file not  yet  opened, 
  696.                this  is generated on the disk (any existing  file 
  697.                of the same name will be deleted!) and opened  for 
  698.                writing.
  699.  
  700. telling( TERM )
  701.                attempts  to unify the parameter with the  current 
  702.                output stream.
  703.  
  704. told
  705.                If  the  current output stream is a  file,  it  is 
  706.                closed.  The predefined data stream 'user' becomes 
  707.                the current output stream.
  708.  
  709.  
  710. Access  to  disk directories is enabled by the  following  system 
  711. functions, implemented in Version 3.3:
  712.  
  713. disk_dir( VAR )
  714.                instantiates  PAR_1 with the name of  the  current 
  715.                directory, i.e. drive descriptor and pathname.
  716.  
  717. disk_dir( NAME )
  718.                makes  the  directory given in PAR_1  the  current 
  719.                directory.  The drive descriptor can be absent; in 
  720.                this case the current drive is used.  If PAR_1  is 
  721.                incorrect, a system call error is generated.
  722.  
  723. disk_search( NAME, INTEGER, TERM, TERM )
  724.                PAR_1  and PAR_2 are parameters for the  operating 
  725.                system  call  'Fsfirst':  the first  file  in  the 
  726.                current directory (or in a directory determined by 
  727.  
  728. TOY Prolog ST                  15                    File streams
  729.  
  730.  
  731.                a  pathname  present in  PAR_1)  is  sought,  that 
  732.                corresponds  to the search pattern in  PAR_1,  and 
  733.                whose   attributes   correspond  to   the   search 
  734.                attributes PAR_2. The search pattern is given as a 
  735.                filename;  though the 'wild cards' '#' and '?' can 
  736.                be used here. There must be no 'wild cards' in the 
  737.                pathname.
  738.                     The  search attributes are given  bitwise  in 
  739.                PAR_2:
  740.                     0    Normal file access allowed
  741.                     1    File is write-protected
  742.                     2    File is 'hidden'
  743.                     4    File is a 'system file' (also hidden)
  744.                     8    Not a file, but the name of the disk
  745.                    16    Not a file, but a subdirectory
  746.                    32    File has been written & closed (???)
  747.                If no corresponding file is found, the call fails; 
  748.                otherwise  an attempt is made to unify PAR_3  with 
  749.                the name and PAR_4 with the attributes of the file 
  750.                found.
  751.  
  752. disk_search( TERM, TERM )
  753.                seeks the next file whose name and attributes  fit 
  754.                those  in  the last  call  of  disk_search/4,  and 
  755.                attempts  to  unify PAR_1 with  the  filename  and 
  756.                PAR_2 with the attributes belonging to it.  If  no 
  757.                further file that fits is found, the call fails.
  758.  
  759.  
  760. If  a critical error occurs during a disk operation -  change  of 
  761. disk, wrong disk in drive, etc. - the message results,
  762.        There was a critical error. (A)bort, (R)etry or (I)gnore?
  763. Entering 'A' leads to an abort,  with an error message; 'R' gives 
  764. rise  to  a  new  trial,  and  with  'I'  the  error  is  ignored 
  765. (careful!).
  766.  
  767. TOY Prolog ST                  16                      Input aids
  768.  
  769.  
  770.  
  771.  
  772. 3.2.5.3. Input aids
  773.          ----------
  774. TOY  Prolog  has  the  ability to print out  on  the  screen  for 
  775. checking characters that have been read in from a file stream  or 
  776. a peripheral device.
  777.  
  778. echo
  779.                switches checking printout on.
  780.  
  781. noecho
  782.                switches checking printout off.
  783.  
  784.  
  785. Version  3.3  allows  character strings to  be  assigned  to  the 
  786. function keys (F1 to F10) and the cursor key block,  so that when 
  787. the  appropriate  key is pressed during entry from  the  keyboard 
  788. (data streams 'user' and 'keybd') it is as if the string had been 
  789. entered from the keyboard.
  790.      The following system function serves for this:
  791.  
  792. set_fstring( INTEGER, NAME )
  793.                PAR_1  must  be an integer in the range 0  to  27, 
  794.                which  selects  the  desired  function  key   (see 
  795.                below).  The character string given by the name in 
  796.                PAR_2  is  assigned to the selected  function  key 
  797.                (PAR_2 must be a functor without arguments).
  798.                     The function keys are denoted as follows:
  799.                0   F1       10   Shift-F1       20   Clr/Home
  800.                1   F2       11   Shift-F2       21   Cursor up
  801.                2   F3       12   Shift-F3       22   Cursor left
  802.                3   F4       13   Shift-F4       23   Cursor right
  803.                4   F5       14   Shift-F5       24   Cursor down
  804.                5   F6       15   Shift-F6       25   Insert
  805.                6   F7       16   Shift-F7       26   Undo
  806.                7   F8       17   Shift-F8       27   Help
  807.                8   F9       18   Shift-F9
  808.                9   F10      19   Shift-F10
  809.  
  810.                     This special feature applies to the character 
  811.                string:  if  there  is a '\' in  the  string,  the 
  812.                following  character is interpreted as if the  key 
  813.                concerned had been typed together with  'Control'. 
  814.                Exception:  if the character following is  another 
  815.                '\',  it counts (as usual) as a single '\'.  E.g.: 
  816.                \G - 'Bell', \H - 'Backspace', \M - 'Return'.
  817.  
  818. TOY Prolog ST                  17        I/o of terms - Operators
  819.  
  820.  
  821.  
  822.  
  823. 3.2.5.4. Input/output of terms; operators
  824.          --------------------------------
  825. display( TERM )
  826.                outputs  TERM  in  standard form  to  the  current 
  827.                output stream:  functors will be output in  prefix 
  828.                form  with brackets;  names will not be placed  in 
  829.                apostrophes; variables will be output as _N, where 
  830.                N is a number.
  831.  
  832. write( TERM )
  833.                outputs  TERM to the current  output  stream;  the 
  834.                present  operator declarations will  be  followed, 
  835.                but  names  will  not be  placed  in  apostrophes. 
  836.                Variables will be output in the form XN,  where  N 
  837.                is a number; the numbering begins with 1.
  838.                     Warning:  in  TOY Prolog a predicate is  used 
  839.                for  the  output of variables that  numbers  them, 
  840.                binding them to terms of the form 'V'(N). For this 
  841.                reason,  terms  of  the form 'V'(N)  will  not  be 
  842.                output correctly, when N is an integer number.
  843.  
  844. writeq( TERM )
  845.                As 'write', but names that do not constitute well-
  846.                formed  words  or are in conflict with  a  present 
  847.                operator  declaration will be placed  in  apostro-
  848.                phes.  Terms  that have been output with  'writeq' 
  849.                can be read in again with 'read'.
  850.  
  851. read( TERM )
  852.                reads a term, concluded with a full stop, from the 
  853.                current input stream; succeeds only when this term 
  854.                can  be unified with PAR_1.  The present  operator 
  855.                declarations  are  followed.  If  the  input  term 
  856.                contains a syntactical error, the message
  857.                     "Bad term on input. Text skipped:"
  858.                is output,  and the input text as far as the  next 
  859.                full stop outside a comment or quotation marks  is 
  860.                skipped (if there is no full stop,  the user  must 
  861.                enter one). After that, it attempts to unify PAR_1 
  862.                with 'e r r'.
  863.                     At  the  end  of  a  file  stream,  input  is 
  864.                switched to 'user'.
  865.  
  866. op( INTEGER, ATOM, ATOM )
  867.                declares PAR_3 as an operator with type  specifier 
  868.                PAR_2 and precedence number PAR_1.  Operators with 
  869.                lower precedence numbers are evaluated first.  The 
  870.                precedence must be in the range  1 ≤ PAR_1 ≤ 1200, 
  871.                and  should  be less than 1000 to  avoid  conflict 
  872.                with the operators ',', ';', ':-' and '-->'.
  873.                     PAR_2 must be chosen from the set {  xf,  yf, 
  874.                fx,  fy,  xfx,  xfy,  yfx,  yfy }.  PAR_3 must  be 
  875.  
  876. TOY Prolog ST                  18                       Operators
  877.  
  878.  
  879.                printable without apostrophes.
  880.                     If an operator declaration already exists for 
  881.                PAR_3,  it  is  modified in  accordance  with  the 
  882.                instructions   of  PAR_1  and   PAR_2:   the   new 
  883.                precedence replaces the old and the new unary  (or 
  884.                binary)  type replaces the old unary  (or  binary) 
  885.                type.  In TOY Prolog an operator can have only one 
  886.                unary and one binary type at the same  time,  both 
  887.                with the same precedence.
  888.  
  889. delop( ATOM )
  890.                deletes the operator declaration for PAR_1.  PAR_1 
  891.                should be placed in apostrophes, as it is still an 
  892.                operator up to the moment of entry of 'delop'.
  893.  
  894. The following standard operators are declared already:
  895.  
  896.             Operator     Type       Precedence
  897.                :-      xfx, fx         1200
  898.               -->        xfx           1200
  899.                ;         xfy           1100
  900.                ,         xfy           1000
  901.               not         fy            900
  902.                =         xfx            700
  903.                is        xfx            700
  904.               =:=        xfx            700
  905.               =\=        xfx            700
  906.                <         xfx            700
  907.                =<        xfx            700
  908.                >         xfx            700
  909.                >=        xfx            700
  910.                @<        xfx            700
  911.               @=<        xfx            700
  912.                @>        xfx            700
  913.               @>=        xfx            700
  914.                ==        xfx            700
  915.               \==        xfx            700
  916.               =..        xfx            700
  917.                +       yfx, fx          500
  918.                -       yfx, fx          500
  919.                *         yfx            400
  920.                /         yfx            400
  921.               mod        xfx            300
  922.  
  923. TOY Prolog ST                  19               Single characters
  924.  
  925.  
  926.  
  927.  
  928. 3.2.5.5. Single characters
  929.          -----------------
  930. In TOY Prolog,  unlike Prolog-10, single characters are represen-
  931. ted  by atoms,  whose names consist of exactly one character  (in 
  932. Prolog-10, as their ASCII-representation, i.e. as numbers).
  933.      TOY  Prolog ST supports the extended character set  of  GEM; 
  934. hence German,  French,  Spanish etc.  letters are actually recog-
  935. nized as letters (!).
  936.      For  character strings  there  exists  a  special  represen-
  937. tational  form.   Character strings  are  treated  as  lists   of 
  938. single characters  (not,  as  in Prolog-10,  as  lists  of  ASCII 
  939. codes);  the notation for character strings uses quotation  marks 
  940. (") to enclose a string.  As usual, a doubled quotation mark ("") 
  941. inside  a  character string denotes a single "  included  in  the 
  942. string.
  943.  
  944. The  following  predicates  are provided for  working  on  single 
  945. characters.
  946.  
  947. ordchr( INTEGER, CHAR )
  948.                succeeds  whenever PAR_1 is the ordinal number  of 
  949.                the character PAR_2.
  950.  
  951. ordchr( VAR, CHAR )
  952.                succeeds  after  unifying PAR_1 with  the  ordinal 
  953.                number of PAR_2.
  954.  
  955. ordchr( INTEGER, VAR )
  956.                succeeds  after unifying PAR_2 with the  character 
  957.                whose ordinal number PAR_1 mod 256 is.
  958.  
  959. iseoln( TERM )
  960.                attempts  to  unify  PAR_1  with  the  end_of_line 
  961.                character.  TOY Prolog converts every  end_of_line 
  962.                to a single 'CR'.
  963.  
  964. smalletter( TERM )
  965.                tests whether PAR_1 is a lower-case letter.
  966.  
  967. bigletter( TERM )
  968.                tests whether PAR_1 is a capital letter.
  969.  
  970. letter( TERM )
  971.                tests whether PAR_1 is a letter.
  972.  
  973. digit( TERM )
  974.                tests whether PAR_1 is a decimal digit.
  975.  
  976. alphanum( TERM )
  977.                tests whether PAR_1 is a letter,  digit or  under-
  978.                score (_).
  979.  
  980.  
  981. TOY Prolog ST                  20               Single characters
  982.  
  983.  
  984. bracket( TERM )
  985.                tests whether PAR_1 is one of the characters ( ) [ 
  986.                ] { }
  987.  
  988. solochar( TERM )
  989.                tests whether PAR_1 is one of the characters ! , ;
  990.  
  991. symch( TERM )
  992.                tests whether PAR_1 is a symbol_char.
  993.  
  994.  
  995. 3.2.5.6. Input/output of single characters
  996.          ---------------------------------
  997. For the input and output of single characters there are a  number 
  998. of special predicates. These do not work - as in Prolog-10 - with 
  999. ASCII  codes.  The predicates of Prolog-10 that deal with i/o  of 
  1000. single  characters can be defined roughly as follows  (not  fully 
  1001. compatible):
  1002.  
  1003.      get0(Ord) :- rch, lastch(Ch), ordchr(Ord, Ch).
  1004.      get(Ord)  :- rch, skipbl, lastch(Ch), ordchr(Ord, Ch).
  1005.      skip(X)   :- repeat, get0(X), !.
  1006.      put(Ord)  :- ordchr(Ord, Ch), wch(Ch).
  1007.  
  1008. The  main  difference  between TOY Prolog and  Prolog-10  in  the 
  1009. handling  of single characters lies in the fact that  TOY  Prolog 
  1010. maintains  a buffer for the last character input;  hence  in  TOY 
  1011. Prolog  an  entered character can be  accessed  repeatedly,  even 
  1012. after possible backtracking.
  1013.  
  1014. If an end_of_line is reached during input, it is written into the 
  1015. input buffer ("last_char") as a single 'CR'. If the end of a file 
  1016. stream  is reached,  the interpreter automatically  executes  the 
  1017. predicate 'seen';  the following character will be read from  the 
  1018. user  stream.  This  event  will be reported to  the  user  by  a 
  1019. message.
  1020.  
  1021. The predicates for i/o of single characters:
  1022.  
  1023. rch
  1024.                succeeds after writing the next character from the 
  1025.                current input stream into last_char.
  1026.  
  1027. skipbl
  1028.                succeeds after ensuring that last_char contains  a 
  1029.                printable character (ASCII code > 32).  If such  a 
  1030.                character is already present in last_char, nothing 
  1031.                is done, otherwise 'rch' is executed.
  1032.  
  1033. lastch( TERM )
  1034.                attempts to unify PAR_1 with last_char.
  1035.  
  1036.  
  1037. TOY Prolog ST                  21     Single chars - Type testing
  1038.  
  1039.  
  1040. rdch( TERM )
  1041.                reads the next character from the input stream and 
  1042.                writes  it  into  last_char;   makes  a  copy   of 
  1043.                last_char,  in  which unprintable  characters  are 
  1044.                replaced by spaces; and attempts to unify the copy 
  1045.                with PAR_1.
  1046.  
  1047. rdchsk( TERM )
  1048.                as 'rdch', but 'skipbl' is executed first.
  1049.  
  1050. wch( CHAR )
  1051.                writes  the  character  into  the  current  output 
  1052.                stream. 'CR' is interpreted as a line-separator.
  1053.  
  1054. nl
  1055.                ends the current line (outputs 'CR').
  1056.  
  1057. bell
  1058.                outputs the character 'BEL'; on output to the user 
  1059.                stream this character produces a bell sound.
  1060.  
  1061. The Atari ST interprets the character 'Esc' (Escape) as a special 
  1062. control character:  when 'Esc' is output to the user stream,  the 
  1063. next  1-3  characters produce a change of the parameters  of  the 
  1064. screen output.  There exist special predicates for the output  of 
  1065. escape sequences:
  1066.  
  1067. escape
  1068.                outputs 'Esc'.
  1069.  
  1070. cls
  1071.                outputs  'Esc',   'E';   this  erases  the  screen 
  1072.                contents.
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079. 3.2.6. Type testing
  1080.        ------------
  1081. var( TERM )
  1082.                succeeds whenever PAR_1 is a free variable.
  1083.  
  1084. integer( TERM )
  1085.                succeeds whenever PAR_1 is an integer number.
  1086.  
  1087. nonvarint( TERM )
  1088.                succeeds whenever PAR_1 is an F_TERM.
  1089.  
  1090. atom( TERM )
  1091.                succeeds whenever PAR_1 is an atom.
  1092.  
  1093. TOY Prolog ST                  22              The term structure
  1094.  
  1095.  
  1096.  
  1097.  
  1098. 3.2.7. Access to the term structure
  1099.        ----------------------------
  1100. pname( NAME, TERM )
  1101.                generates  a list of the individual characters  of 
  1102.                PAR_1 and attempts to unify this list with PAR_2.
  1103.  
  1104. pname( VAR, CHAR_LIST )
  1105.                succeeds  after  unifying PAR_1 with a  NAME  that 
  1106.                consists of the individual characters of PAR_2.
  1107.  
  1108. pnamei( INTEGER, TERM )
  1109.                generates  a list of digits that form the  decimal 
  1110.                representation  of PAR_1,  and attempts  to  unify 
  1111.                this list with PAR_2. PAR_1 must not be negative.
  1112.  
  1113. pnamei( VAR, NUM_LIST )
  1114.                succeeds  after  unifying PAR_1 with  the  integer 
  1115.                number   whose  decimal  representation   is   the 
  1116.                characters of PAR_2. Even with correct parameters, 
  1117.                an  error  can  occur if the  number  exceeds  the 
  1118.                biggest representable integer. In this implementa-
  1119.                tion  numbers  up  to 32767  ( = 2**15  -  1)  are 
  1120.                representable.
  1121.  
  1122. 'pname'  and 'pnamei' replace the function 'name'  of  Prolog-10, 
  1123. which  in fact works similarly,  but uses ASCII codes instead  of 
  1124. the character representation used in TOY Prolog.
  1125.  
  1126. functor( VAR, INTEGER, 0 )
  1127.                PAR_3  is the number 0;  this call succeeds  after 
  1128.                unifying PAR_1 with PAR_2.
  1129.  
  1130. functor( VAR, NAME, INTEGER )
  1131.                succeeds after unifying PAR_1 with an F_TERM whose 
  1132.                functor has the name and arity determined by PAR_2 
  1133.                and  PAR_3  and whose arguments are  various  free 
  1134.                variables. PAR_3 must not be negative.
  1135.  
  1136. functor( INTEGER, TERM, TERM )
  1137.                attempts to unify PAR_2 with PAR_1 and PAR_3  with 
  1138.                the number 0.
  1139.  
  1140. functor( F_TERM, TERM, TERM )
  1141.                attempts  to unify PAR_2 with the name  and  PAR_3 
  1142.                with the arity of the principal functor of PAR_1.
  1143.  
  1144. arg( INTEGER, F_TERM, TERM )
  1145.                fails if PAR_1 is less than 1 or greater than  the 
  1146.                arity of the principal functor of PAR_2; otherwise 
  1147.                it  attempts  to  unify  PAR_3  with  the  PAR_1th 
  1148.                argument of PAR_2.
  1149.  
  1150.  
  1151. TOY Prolog ST                  23              The term structure
  1152.  
  1153.  
  1154. VAR =.. [INTEGER]
  1155.                succeeds  after unifying PAR_1 with the number  in 
  1156.                PAR_2.
  1157.  
  1158. VAR =.. [NAME | TERM]
  1159.                If  the  TERM  in PAR_2 is not  a  'closed'  list, 
  1160.                generates  an  error in the  predicate  length / 2 
  1161.                ('=..' uses 'length').  Otherwise generates a term 
  1162.                whose  functor is NAME and whose argument list  is 
  1163.                TERM; this term will be unified with PAR_1.
  1164.  
  1165. INTEGER =.. TERM
  1166.                attempts to unify PAR_2 with [PAR_1].
  1167.  
  1168. F_TERM =.. TERM
  1169.                generates  a  list  whose head  is  the  principal
  1170.                functor of PAR_1 and whose body the argument  list 
  1171.                of PAR_1; attempts to unify this list with PAR_2.
  1172.  
  1173. TOY Prolog ST                  24            The Prolog data bank
  1174.  
  1175.  
  1176.  
  1177.  
  1178. 3.2.8. Access to predicates in the data bank
  1179.        -------------------------------------
  1180. protect( NAME, INTEGER )
  1181.                protects  the predicate with name PAR_1 and  arity 
  1182.                PAR_2  against  alteration by the  predicates  de-
  1183.                clared further on.
  1184.  
  1185. protect
  1186.                protects  all the predicates present in  the  data 
  1187.                bank.
  1188.  
  1189. unprotect( NAME, INTEGER )
  1190.                removes the protection for the predicate with name 
  1191.                PAR_1 and arity PAR_2.
  1192.  
  1193. unprotect
  1194.                removes the protection from all predicates.
  1195.  
  1196. The data bank can be altered through the following predicates:
  1197.  
  1198. assert( F_TERM, CALL_LIST, INTEGER )
  1199.                PAR_1 will be regarded as the head of a clause and 
  1200.                PAR_2 as its body; this clause will be inserted in 
  1201.                the data bank directly after the nth clause of the 
  1202.                relevant procedure ( n = PAR_3, if the clause with 
  1203.                this number exists; the number of the last clause, 
  1204.                if there are < PAR_3 clauses;  or 0, if no clauses 
  1205.                exist or PAR_3 < 1 ).
  1206.  
  1207. retract( NAME, INTEGER, INTEGER )
  1208.                PAR_2  must  not  be  negative.  PAR_1  and  PAR_2 
  1209.                indicate the name and arity of a predicate; if the 
  1210.                relevant  predicate has no clause with the  number 
  1211.                PAR_3,  'retract'  fails;  otherwise the  relevant 
  1212.                clause  will  be removed from the  data  bank  and 
  1213.                'retract' will succeed.
  1214.                     Warning:  if instances of the deleted  clause 
  1215.                are still active at the moment of deletion, in the 
  1216.                great  majority of cases catastrophic errors  will 
  1217.                occur!
  1218.  
  1219. clause( NAME, INTEGER, INTEGER, TERM, TERM )
  1220.                PAR_2  must  not  be  negative.  PAR_1  and  PAR_2 
  1221.                indicate the name and arity of a predicate; if the 
  1222.                relevant  predicate has no clause with the  number 
  1223.                PAR_3,  'clause' fails;  otherwise it attempts  to 
  1224.                unify PAR_4 with its head and PAR_5 with its body.
  1225.  
  1226.  
  1227. TOY Prolog ST                  25            The Prolog data bank
  1228.  
  1229.  
  1230. asserta( F_TERM )
  1231.                treats PAR_1 as a clause; if the principal functor 
  1232.                is ':-' and its first argument not an  F_TERM,  an 
  1233.                error is generated. The clause will be inserted in 
  1234.                the data bank as the first clause of the  relevant 
  1235.                predicate.
  1236.  
  1237. assertz( F_TERM )
  1238.                As  'asserta',  but  inserts  the  clause  in  the 
  1239.                data  bank  as  the last clause  of  the  relevant 
  1240.                predicate.
  1241.  
  1242. assert( F_TERM )
  1243.                a synonym for 'asserta'.
  1244.  
  1245. retract( F_TERM )
  1246.                treats PAR_1 as a clause; if its principal functor 
  1247.                is ':-' and its first argument not an  F_TERM,  an 
  1248.                error is generated.  The first clause that can  be 
  1249.                unified  with PAR_1 will be removed from the  data 
  1250.                bank (if PAR_1 has the form F_TERM :- VAR,  it can 
  1251.                only  be unified with clauses whose body  consists 
  1252.                of a single variable-call!).  If 'retract'  should 
  1253.                be  resatisfied,  the next clause  unifiable  with 
  1254.                PAR_1 will be removed, and so on.
  1255.  
  1256. clause( F_TERM, TERM )
  1257.                finds  the first clause whose head can be  unified 
  1258.                with  PAR_1 and whose body  with  PAR_2;  succeeds 
  1259.                after  successful  unification.   If  'clause'  is 
  1260.                resatisfied, the next clause is looked for, and so 
  1261.                on.
  1262.  
  1263. redefine
  1264.                is  needed for the implementation  of  'reconsult' 
  1265.                (it  should not be called directly).  Between  two 
  1266.                calls to 'redefine',  'assert' behaves differently 
  1267.                from  normal:  if a clause is saved with  'assert' 
  1268.                that  does not belong to the predicate last  saved 
  1269.                with 'assert',  the entire predicate to which  the 
  1270.                new clause belongs will first be deleted.
  1271.  
  1272. abolish( NAME, INTEGER )
  1273.                PAR_2  must not be negative.  The  predicate  with 
  1274.                name  PAR_1  and  arity  PAR_2  will  be  entirely 
  1275.                deleted.
  1276.  
  1277. predefined( NAME, INTEGER )
  1278.                PAR_2  must not be  negative;  'predefined'  tests 
  1279.                whether   the  predicate  with  name   PAR_1   and 
  1280.                arity PAR_2 is a system function.
  1281.  
  1282.  
  1283. TOY Prolog ST                  26            The Prolog data bank
  1284.  
  1285.  
  1286. consult( FILENAME )
  1287.                switches  the  current  input  stream  and   reads 
  1288.                clauses, which it then saves with 'assertz'. There 
  1289.                are  two exceptions to this:  the term 'end'  ends 
  1290.                the  read-in  mode  and  restores  the  old  input 
  1291.                stream; terms with the functor ':-'/1 are regarded
  1292.                as commands and executed accordingly.
  1293.  
  1294. reconsult( FILENAME )
  1295.                as  'consult',  but  before and after  reading  in 
  1296.                'redefine'  is called,  so that  connected  conse-
  1297.                quences of the clauses of a predicate replace  the 
  1298.                old predicate, instead of supplementing it.
  1299.  
  1300. consultall( TERM )
  1301.                PAR_1 must be a list of FILENAMEs or terms of  the 
  1302.                form  '-  FILENAME' (also  mixed);  it  will  call 
  1303.                'consult' for each simple FILENAME and 'reconsult' 
  1304.                for  each FILENAME with '-'/1.  This predicate  is 
  1305.                called  by  the  user interface  when  a  list  of 
  1306.                commands is entered.
  1307.  
  1308. listing( F_TERM )
  1309.                PAR_1  must  be an ATOM,  or a term  of  the  form 
  1310.                ATOM/INTEGER, or a (possibly complex) list of such 
  1311.                terms;  each ATOM is regarded as the name and each 
  1312.                number  as the arity of a predicate.  All  clauses 
  1313.                belonging  to  the  pertinent  predicate  will  be 
  1314.                output to the current output stream.
  1315.  
  1316. listing
  1317.                as   listing/1,   but  outputs   all   predicates, 
  1318.                including the predefined predicates.  The sequence 
  1319.                is  fixed  by  the 'hash' function  of  the  inner 
  1320.                interpreter and cannot be altered.
  1321.  
  1322. proc( TERM )
  1323.                attempts  to unify PAR_1 with an F_TERM  that  has 
  1324.                the  name and arity of the first predicate in  the 
  1325.                data bank;  should 'proc' be resatisfied, the next 
  1326.                predicate is used each time;  fails if there is no 
  1327.                further such predicate there.  For the sequence of 
  1328.                the predicates, see listing/0.
  1329.  
  1330. TOY Prolog ST                  27          Program course control
  1331.  
  1332.  
  1333.  
  1334.  
  1335. 3.2.9. Control of the course of the program
  1336.        ------------------------------------
  1337. When  the call of a predicate activates a clause that is not  the 
  1338. last one of this predicate,  a pointer is assigned to this clause 
  1339. in the data bank.  This pointer is used when the goal called  has 
  1340. to be resatisfied.
  1341.      The  direct  descendants of a call A are the  calls  in  the 
  1342. clause  activated  by A.  The direct ancestor of A  is  the  call 
  1343. activated  by the clause in which A occurs.  An ancestor of A  is 
  1344. the  direct  ancestor or an ancestor of the  direct  ancestor;  a 
  1345. descendant of A is a direct descendant or one of its descendants.
  1346.  
  1347. !  ('cut', sometimes also 'slash')
  1348.                succeeds  after finding the next ancestor that  is 
  1349.                not  call/1,  tag/1,  ,/2 or  ;/2.  All  data-bank 
  1350.                pointers that belong to this ancestor and all  its 
  1351.                descendants are removed.
  1352.  
  1353. repeat
  1354.                succeeds,  and can be resatisfied as often as  you 
  1355.                like.
  1356.  
  1357. call( CALL )
  1358.                behaves as though PAR_1 stood in the place of  the 
  1359.                call  of  'call';  though when 'call' is used,  an 
  1360.                incorrect parameter is first recognised at the run 
  1361.                time  of the program.  In the outer interpreter  a 
  1362.                variable can occur in place of a predicate as call 
  1363.                in a clause;  such a variable-call is converted by 
  1364.                the outer interpreter into a call of 'call'.
  1365.  
  1366. tag( CALL )
  1367.                another form of call(CALL); a call of 'tag' can be 
  1368.                accessed with the predicates 'tagfail', 'tagexit', 
  1369.                'tagcut'  and  'ancestor'.  PAR_1  is  called  the 
  1370.                marked ancestor of its descendants.
  1371.                     A  call of 'tag' is recognized  by  'tagfail' 
  1372.                etc.  only when it stands explicitly in a  clause, 
  1373.                e.g. call(tag(A)) is not recognised.
  1374.  
  1375. ancestor( TERM )
  1376.                seeks the next marked ancestor that can be unified 
  1377.                with PAR_1;  if none is found,  'ancestor'  fails, 
  1378.                otherwise  the ancestor and PAR_1 are unified  and 
  1379.                'ancestor' succeeds.
  1380.  
  1381. tagcut( TERM )
  1382.                as  'ancestor',  but on success all the  data-bank 
  1383.                pointers  belonging to the ancestor found and  its 
  1384.                descendants are removed.
  1385.  
  1386.  
  1387. TOY Prolog ST                  28          Program course control
  1388.  
  1389.  
  1390. tagfail( TERM )
  1391.                seeks the next marked ancestor that can be unified 
  1392.                with PAR_1;  fails if none is found.  If a  marked 
  1393.                ancestor is found, this fails at once.
  1394.  
  1395. tagexit( TERM )
  1396.                seeks the next marked ancestor that can be unified 
  1397.                with PAR_1;  fails if none is found.  If a  marked 
  1398.                ancestor  is found,  it is unified with PAR_1  and 
  1399.                succeeds at once (i.e.  the call after tag(...) is 
  1400.                considered as the next).
  1401.  
  1402. halt( ATOM )
  1403.                outputs PAR_1 and ends the inner interpreter.
  1404.  
  1405. stop
  1406.                ends  the  main  loop of  the  outer  interpreter; 
  1407.                normally 'halt' is called and the inner  interpre-
  1408.                ter ended as well.  Exceptions are possible  (e.g. 
  1409.                in the editor).
  1410.  
  1411. sysload( FILENAME )
  1412.                ends  the  outer  interpreter  and  switches   the 
  1413.                current input stream to the given file.  This file 
  1414.                should  contain  a program in the  syntax  of  the 
  1415.                inner  interpreter  (see  Appendix  2).   After  a 
  1416.                'seen',  or on reaching the end of the  file,  the 
  1417.                outer interpreter is restarted.
  1418.  
  1419. TOY Prolog ST                  29                 Program testing
  1420.  
  1421.  
  1422.  
  1423.  
  1424. 3.2.10. Aids for the testing of programs
  1425.         --------------------------------
  1426. In  the  ST  version of TOY Prolog there  is  the  possibility of 
  1427. interrupting  the  course  of  a  program  by  pressing  the  key 
  1428. combination ShiftAlternateHelp. The present goal is output in the 
  1429. form
  1430.           INTR: .......
  1431. and  the  user  has the opportunity to alter the  course  of  the 
  1432. program. For this s/he can select the following options:
  1433.  
  1434. A  (Abort)     The  entire goal being carried out is  broken  off 
  1435.                (including the outer interpreter).
  1436. B  (Backtrace) The ancestors of the present goal are reported.
  1437. C  (Continue)  The present goal is worked on.
  1438. D  (Debug ON/OFF)  Test mode is switched on or off (see 'debug').
  1439. F  (Fail)      The present goal fails.
  1440. S  (Step ON/OFF)  Single-step mode is switched on or off;  if  it 
  1441.                is  switched  on,  the  program  is  automatically 
  1442.                interrupted before working on the next goal.
  1443.  
  1444. Pressing  the  key  combination 'Control-C' often  has  the  same 
  1445. effect as ShiftAltHelp followed by selecting option A:  the outer 
  1446. interpreter is immediately stopped.  The inner interpreter is not 
  1447. stopped;  if  no  file  is being read in  just  then,  the  outer 
  1448. interpreter is restarted.
  1449.  
  1450. In addition there exist some predicates that should make  program 
  1451. testing easier:
  1452.  
  1453. interrupt
  1454.                interrupts  the course of the program (as  if  the 
  1455.                user had pressed the 'Help' key).
  1456.  
  1457. debug
  1458.                switches test mode on.  In test mode, each goal to 
  1459.                be  worked  on  is printed  out  with  information 
  1460.                reporting whether the goal
  1461.                - is being called for the first time    (CALL:...)
  1462.                - is to be resatisfied                  (REDO:...)
  1463.                - has been successfully completed       (EXIT:...)
  1464.                - or has failed                         (FAIL:...)
  1465.  
  1466. nodebug
  1467.                switches test mode off.
  1468.  
  1469. nonexistent
  1470.                switches  on  monitoring  of  calls  of  undefined 
  1471.                predicates. After 'nonexistent', in case of a call 
  1472.                of  an  undefined  predicate  a  message  will  be 
  1473.                output.
  1474.  
  1475.  
  1476. TOY Prolog ST                  30           Program testing, etc.
  1477.  
  1478.  
  1479. nononexistent
  1480.                switches these messages off again.
  1481.  
  1482. The following two predicates switch test mode on selectively  for 
  1483. set calls:
  1484.  
  1485. spy( NAME, INTEGER )
  1486.                PAR_2 must not be negative.  Test mode is switched 
  1487.                on  for  the predicate with name PAR_1  and  arity 
  1488.                PAR_2.
  1489.  
  1490. spy( NAME, VAR )
  1491.                ditto,  but for all predicates with this name; the 
  1492.                variable is not instantiated.
  1493.  
  1494. spy( VAR, INTEGER )
  1495.                ditto,  but  for  all predicates  with  the  given 
  1496.                arity.
  1497.  
  1498. spy( VAR, VAR )
  1499.                ditto,  but for all predicates.  The effect is the 
  1500.                same as with 'debug',  but cannot be switched  off 
  1501.                again with 'nodebug' (!). As the variables are not 
  1502.                instantiated, the same variable can be used twice.
  1503.  
  1504. nospy( PAR1, PAR2 )
  1505.                switches off the selective test mode. All the call 
  1506.                patterns  of 'spy' can be used in the same way  as 
  1507.                there.  'nospy' cannot switch off the general test 
  1508.                mode switched on with 'debug'.
  1509.  
  1510. spied( NAME, INTEGER )
  1511.                tests whether the selective test mode is  switched 
  1512.                on  for  the predicate with name PAR_1  and  arity 
  1513.                PAR_2.
  1514.  
  1515. Note:  at present test mode does not function correctly - FAIL is 
  1516. often  reported  when  it should not  be,  and  EXIT  not  always 
  1517. reported when it should be. See Appendix 5.
  1518.  
  1519.  
  1520. 3.2.11. Working on grammatical rules
  1521.         ----------------------------
  1522. phrase( CALL, TERM )
  1523.                treats PAR_1 as a non-terminal symbol of a gramma-
  1524.                tical  rule  and arranges for  the  processing  of 
  1525.                PAR_2 using PAR_1 as start symbol.
  1526.  
  1527.  
  1528. 3.2.12. Miscellaneous functions
  1529.         -----------------------
  1530. length( F_TERM, TERM )
  1531.                computes  the  length of PAR_1,  which must  be  a 
  1532.                'closed'  list,  and attempts to unify the  result 
  1533.  
  1534. TOY Prolog ST                  31         Miscellaneous functions
  1535.  
  1536.  
  1537.                with PAR_2.
  1538.  
  1539. isclosedlist( TERM )
  1540.                tests whether PAR_1 is a 'closed' list.
  1541.  
  1542. numbervars( TERM )
  1543.                instantiates  the  variables that occur  in  PAR_1 
  1544.                with 'V'(1),  'V'(2),  ...  .  Variables that have 
  1545.                been bound together are instantiated with the same 
  1546.                'V'(n).
  1547.  
  1548. member( TERM, TERM )
  1549.                tests  whether  PAR_1 is an element  of  the  list 
  1550.                PAR_2.  If  PAR_2 is an 'open' list that does  not 
  1551.                contain  PAR_1,  'member' succeeds after the  list 
  1552.                has been extended to include PAR_1.
  1553.  
  1554. bagof( TERM, CALL, TERM )
  1555.                attempts  to  unify  PAR_3  with  a  list  of  the 
  1556.                instantiations  established  for PAR_1  after  all 
  1557.                possible computations of PAR_2.
  1558.  
  1559. status
  1560.                gives an overview of present memory occupancy.
  1561.  
  1562. The following predicates use the Atari ST's clock:
  1563.  
  1564. date( VARINT, VARINT, VARINT )
  1565.                attempts  to  unify PAR_1,  PAR_2 and  PAR_3  with 
  1566.                numbers giving the date in the form  "day,  month, 
  1567.                year".
  1568.  
  1569. set_date( INTEGER, INTEGER, INTEGER )
  1570.                sets the date: PAR_1 day, PAR_2 month, PAR_3 year.
  1571.  
  1572. time( VARINT, VARINT, VARINT )
  1573.                attempts  to  unify PAR_1,  PAR_2 and  PAR_3  with 
  1574.                numbers giving the time of day in the form "hours, 
  1575.                minutes, seconds".
  1576.  
  1577. set_time( INTEGER, INTEGER, INTEGER )
  1578.                sets the time:  PAR_1 hours,  PAR_2 minutes, PAR_3 
  1579.                seconds.
  1580.  
  1581. 'time' and 'set_time' work in units of 2 seconds.
  1582.  
  1583.  
  1584. translate( FILENAME, FILENAME )
  1585.                switches  input to PAR_1 and output to  PAR_2  and 
  1586.                translates  the program read from PAR_1  into  the 
  1587.                syntax of the inner interpreter.  The result is  a 
  1588.                file that can be read with 'sysload'.
  1589.                     See  also  the  sections  on  'consult'   and 
  1590.                'sysload', as well as the Appendix.
  1591.  
  1592. TOY Prolog ST                  32          GEM graphics functions
  1593.  
  1594.  
  1595.  
  1596.  
  1597. 3.3. The GEM Functions
  1598.      -----------------
  1599. TOY  Prolog  ST can access some of the functions of the  VDI  and 
  1600. AES. Details of these functions cannot be given here.
  1601.  
  1602. In the following brief descriptions,  all parameters are  INTEGER 
  1603. numbers unless otherwise stated.
  1604.  
  1605. 3.3.1. Control functions
  1606.        -----------------
  1607. grf_clip( Flag, X1, Y1, X2, Y2 )
  1608.                If Flag = 0,  clipping is switched off,  otherwise 
  1609.                on.  (X1, Y1) and (X2, Y2) are diagonally opposite 
  1610.                corners of the clipping rectangle.
  1611.  
  1612. grf_wrmode( Mode )
  1613.                sets the write mode:
  1614.                     0    Replace mode
  1615.                     1    Transparent mode
  1616.                     2    XOR mode
  1617.                     3    Reverse-transparent mode
  1618.  
  1619. grf_colour( Index, Red, Green, Blue )
  1620.                sets  the colour combination for the  colour  with 
  1621.                the given index number. Red, Green and Blue lie in 
  1622.                the range 1 - 1000.
  1623.  
  1624. grf_mode
  1625.                switches graphic mode on.
  1626.  
  1627. txt_mode
  1628.                switches text mode on.
  1629.  
  1630.  
  1631. 3.3.2. Graphic output
  1632.        --------------
  1633. grf_pline( coordinate-list )
  1634.                PAR_1  must  be  a  list  of  an  even  number  of 
  1635.                INTEGERs.  Each pair of list elements is  regarded 
  1636.                as  coordinates  and  a  polyline  (multiple  line 
  1637.                segments) is drawn.
  1638.  
  1639. grf_pmarker( coordinate-list )
  1640.                draws a number of markers at the coordinates given 
  1641.                by PAR_1.
  1642.  
  1643. grf_poly( coordinate-list )
  1644.                draws a filled polygon.
  1645.  
  1646.  
  1647. TOY Prolog ST                  33          GEM graphics functions
  1648.  
  1649.  
  1650. grf_fill( X, Y, Index )
  1651.                fills  an area up to its boundary,  starting  from 
  1652.                the  point (X, Y).  Index is the  original  colour 
  1653.                index of the area (i.e. of the boundary).
  1654.  
  1655. grf_box( X1, Y1, X2, Y2 )
  1656.                draws  a  filled rectangular  area;  (X1, Y1)  and 
  1657.                (X2, Y2) are opposite corners.
  1658.  
  1659. grf_bar( X1, Y1, X2, Y2 )
  1660.                ditto, but with perimeter.
  1661.  
  1662. grf_arc( X, Y, R, Alpha, Omega )
  1663.                draws a circular arc with centre (X, Y), radius R, 
  1664.                start angle Alpha and end angle Omega.
  1665.  
  1666. grf_pie( X, Y, R, Alpha, Omega )
  1667.                ditto, but a filled sector of a circle.
  1668.  
  1669. grf_circle( X, Y, R )
  1670.                draws  a  filled  circle with  centre  (X, Y)  and 
  1671.                radius R.
  1672.  
  1673. grf_ellipse( X, Y, Xrad, Yrad )
  1674.                draws  a  filled ellipse with  centre  (X, Y)  and 
  1675.                semi-axes Xrad and Yrad.
  1676.  
  1677. grf_rbox( X1, Y1, X2, Y2 )
  1678.                draws an unfilled rectangle with rounded corners.
  1679.  
  1680. grf_rfbox( X1, Y1, X2, Y2 )
  1681.                as 'grf_rbox', but filled.
  1682.  
  1683. grf_text( X, Y, Text )
  1684.                Text is a NAME, which is output as graphic text at 
  1685.                the position (X, Y).
  1686.  
  1687.  
  1688. 3.3.3. Attribute functions
  1689.        -------------------
  1690. grf_l_colour( Index )
  1691.                sets the line colour.
  1692.  
  1693. grf_l_type( Style )
  1694.                sets the line type:
  1695.                     1      solid
  1696.                   2 - 6    broken
  1697.                     7      user-defined
  1698.  
  1699. grf_l_udstyle( Pattern )
  1700.                sets  the user-defined line style.  Pattern is  an 
  1701.                INTEGER number whose 16 bits define the pattern.
  1702.  
  1703.  
  1704. TOY Prolog ST                  34          GEM graphics functions
  1705.  
  1706.  
  1707. grf_l_width( Width )
  1708.                sets the line width.
  1709.  
  1710. grf_l_ends( Begin, End )
  1711.                sets the shapes of the start and end of lines:
  1712.                     0    squared
  1713.                     1    arrow
  1714.                     2    rounded
  1715.  
  1716. grf_m_colour( Index )
  1717.                sets the colour of markers.
  1718.  
  1719. grf_m_type( Type )
  1720.                sets the marker type:
  1721.                     1    dot
  1722.                     2    cross
  1723.                     3    asterisk
  1724.                     4    square
  1725.                     5    diagonal cross
  1726.                     6    diamond
  1727.  
  1728. grf_m_height( Height )
  1729.                sets the height of markers.
  1730.  
  1731. grf_t_height( Height )
  1732.                sets the height of text.
  1733.  
  1734. grf_t_point( Height )
  1735.                sets the text height in points.
  1736.  
  1737. grf_t_rotation( Angle )
  1738.                sets the angle to which the character baseline  is 
  1739.                rotated.
  1740.  
  1741. grf_t_colour( Index )
  1742.                sets the text colour.
  1743.  
  1744. grf_t_effects( Effects )
  1745.                sets the text effects. Effects contains the sum of 
  1746.                the effects required:
  1747.                     1    Thickened
  1748.                     2    Light
  1749.                     4    Skewed
  1750.                     8    Underlined
  1751.                    16    Outlined
  1752.  
  1753. grf_t_align( Hor, Vert )
  1754.                sets  the  text alignment horizontally  (Hor)  and 
  1755.                vertically (Vert):
  1756.                Hor:  0    left          Vert:  0    baseline
  1757.                      1    centred              1    half line
  1758.                      2    right                2    ascent line
  1759.                                                3    bottom line
  1760.                                                4    descent line
  1761.  
  1762. TOY Prolog ST                  35          GEM graphics functions
  1763.  
  1764.  
  1765.                                                5    top line
  1766.  
  1767. grf_f_colour( Index )
  1768.                sets the fill colour.
  1769.  
  1770. grf_f_type( Type )
  1771.                sets the interior-fill type:
  1772.                     0    hollow
  1773.                     1    solid
  1774.                     2    patterned
  1775.                     3    hatched
  1776.                     4    user-defined
  1777.  
  1778. grf_f_style( Style )
  1779.                sets the fill style for fill types 2 and 3.
  1780.  
  1781. grf_f_perim( Flag )
  1782.                switches perimeter for filled areas on  (Flag = 1) 
  1783.                or off (Flag = 0).
  1784.  
  1785. grf_f_udpat( Pattern )
  1786.                Pattern  must  be  a list of  exactly  16  INTEGER 
  1787.                numbers.  They will be used as a pattern for  fill 
  1788.                type 4.
  1789.  
  1790.  
  1791. 3.3.4. Functions for mouse control
  1792.        ---------------------------
  1793. grf_mse_hide
  1794.                switches the mouse cursor off.
  1795.  
  1796. grf_mse_show( Flag )
  1797.                If Flag = 0,  switches the mouse on again at once; 
  1798.                otherwise  switches it on when 'grf_mse_show'  has 
  1799.                been  called as many times as  'grf_mse_hide'  has 
  1800.                been previously.
  1801.  
  1802. grf_mse_form( Form )
  1803.                switches on a predefined mouse form:
  1804.                     0    arrow
  1805.                     1    text cursor
  1806.                     2    bee
  1807.                     3    pointing hand
  1808.                     4    flat hand
  1809.                     5    thin crosshairs
  1810.                     6    thick crosshairs
  1811.                     7    outlined crosshairs
  1812.                     255  pencil
  1813.  
  1814. grf_mse_form( Xhot, Yhot, Mask, Data, Pattern )
  1815.                switches on a user-defined mouse form:  Xhot, Yhot 
  1816.                are the coordinates of the action point within the 
  1817.                16x16  grid,  Mask and Data are the background and 
  1818.                foreground  colours;  Pattern  must be a  list  of 
  1819.  
  1820. TOY Prolog ST                  36       GEM functions; system fns
  1821.  
  1822.  
  1823.                exactly  32 INTEGER numbers,  the first 16  giving 
  1824.                the  raster for the mask and the last 16 that  for 
  1825.                the mouse form itself.
  1826.  
  1827. grf_mse_state( Button, X, Y )
  1828.                The  parameters  must  be  variables  or   INTEGER 
  1829.                numbers.  It  attempts  to unify Button  with  the 
  1830.                present state of the mouse buttons and X,  Y  with 
  1831.                the current position of the graphic cursor.
  1832.  
  1833.  
  1834. 3.3.5. Display of an alert message
  1835.        ---------------------------
  1836. alert( Defbutton, Alert, Exbutton )
  1837.                Alert must be a NAME;  the characters of the  name 
  1838.                are treated as a character-string.
  1839.                     Calls  the  AES  function  'form_alert'   and 
  1840.                attempts  to  unify the value  this  returns  with 
  1841.                Exbutton.   Exbutton  must  be  an  INTEGER  or  a 
  1842.                variable.
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851. 3.4. Names of the system functions
  1852.      -----------------------------
  1853. The names of the system functions can be altered, by altering the 
  1854. descriptions  in  the  second section of  the  system  file  (see 
  1855. Appendix 3). In this one must take care that neither the sequence 
  1856. nor the number of the names is altered,  and that the arities are 
  1857. preserved.
  1858.  
  1859. It  is recommended to produce before an alteration a new  version 
  1860. of  the  user  interface,  as after an  alteration  the  previous 
  1861. version  is probably no longer runnable.  The same holds for  all 
  1862. other programs.
  1863.  
  1864. The  names  of the predefined predicates can only be  altered  by 
  1865. altering their definitions in the system file or (with predicates 
  1866. that belong to the user interface) in the source text. The advice 
  1867. above applies here too.
  1868.  
  1869. TOY Prolog ST                  37   Translator for user interface
  1870.  
  1871.  
  1872.  
  1873.  
  1874. 4. THE AUXILIARY PROGRAMS OF TOY PROLOG
  1875.    ------------------------------------
  1876.  
  1877. 4.1. The translator for the User Interface
  1878.      -------------------------------------
  1879. Source code and intermediate code: 'BOOTER.TOY'.
  1880.  
  1881. The  program 'BOOTER.TOY' is needed to provide a new  version  of 
  1882. the  system file after changes to the user  interface.  The  user 
  1883. interface  is not written in complete Prolog but in  a  'slimmed-
  1884. down' version,  which allows easy translation into the syntax  of 
  1885. the inner interpreter.  This is the job the translator takes care 
  1886. of.
  1887.  
  1888. Use of the translator
  1889. ~~~~~~~~~~~~~~~~~~~~~
  1890. To  translate a new version of the user interface,the  translator 
  1891. is loaded with 'sysload'. The call takes place in the form
  1892.  
  1893.      transl( Input_file, Output_file ).
  1894.  
  1895. thus analogous to the predefined predicate 'translate' (3.2.12).
  1896.      '#' is used as the end-of-file character for the input file; 
  1897. if  there  is  not one at the end of the input file  it  must  be 
  1898. entered by hand.
  1899.  
  1900. The  translator  can produce error messages;  in the  process  it 
  1901. gives the name of the predicate the error was detected  in,  with 
  1902. the incorrect characters and the rest of the input as far as  the 
  1903. next full stop.
  1904.  
  1905. If  the  translation runs without error,  the  output  file  will 
  1906. contain  the  intermediate code of the new version  of  the  user 
  1907. interface;  this code - preferably after removing the comments  - 
  1908. can  be  inserted  with  a  text  editor  in  place  of  the  old 
  1909. intermediate code in the system file.  It is advisable to make  a 
  1910. copy of the old (working!) user interface beforehand,  as it  can 
  1911. very  well  happen that the new  version  is  incorrect.  Popular 
  1912. errors  are  the  interchange of upper and  lower  case  letters, 
  1913. especially in variable names,  e.g.  NextCh - Nextch - NextChar - 
  1914. NextChr etc.
  1915.  
  1916. TOY Prolog ST                  38                          Editor
  1917.  
  1918.  
  1919.  
  1920.  
  1921. 4.2. The Editor
  1922.      ----------
  1923. Source: '\SOURCE\EDITOR'.
  1924. Intermediate code: 'EDITOR.TOY'.
  1925.  
  1926. This is a matter of a simple editor for predicates.  It is called 
  1927. with 
  1928.  
  1929.      edit( Name/Arity ).
  1930.  
  1931. The editor shows at any time the current clause together with its 
  1932. number; at the beginning it is at clause 0, i.e. before the first 
  1933. clause. After any command the (new) clause is shown.
  1934.  
  1935. The editor understands the following commands:
  1936.  
  1937. e Name/Arity   calls  a new incarnation of  the  editor.  Another 
  1938.                predicate can be worked on.
  1939.  
  1940. x              (eXit)  leaves  the  present  incarnation  of  the 
  1941.                editor.
  1942.  
  1943. +              shows the next clause, if there is one.
  1944.  
  1945. <CR>           (blankspace) as +.
  1946.  
  1947. -              shows the previous clause (if there is one).
  1948.  
  1949. t              (Top) goes to clause 0.
  1950.  
  1951. b              (Bottom) goes to the last clause.
  1952.  
  1953. l              Lists the entire predicate.
  1954.  
  1955. d              Deletes  the present clause and goes to  the  next 
  1956.                one  (or to the last one,  if the one  before  the 
  1957.                last has been deleted).
  1958.  
  1959. i              (Insert  mode)  Clauses entered in  the  following 
  1960.                lines  will be inserted after the present  clause. 
  1961.                'end.' ends insert mode.
  1962.  
  1963. f Filename     as  'i',  but the clauses are read from the  given 
  1964.                file.
  1965.  
  1966. p              calls a new incarnation of Prolog(!).  When 'stop' 
  1967.                is  executed,  carries on in the  editor.  In  the 
  1968.                encapsulated incarnation of Prolog 'sysload'  must 
  1969.                not be used.
  1970.  
  1971. An entered command must end after the last character. Where blank 
  1972. spaces are given, exactly one must be entered.
  1973.  
  1974. TOY Prolog ST                  39      Program structure analyzer
  1975.  
  1976.  
  1977.  
  1978.  
  1979. 4.3. The Program Structure Analyzer
  1980.      ------------------------------
  1981. Source: '\SOURCE\CALLTREE'.
  1982. Intermediate code: 'CALLTREE.TOY'.
  1983.  
  1984. The program structure analyzer is called with
  1985.  
  1986.      calltree( Name/Arity ).
  1987.  
  1988. to analyse the predicate with the given name and given arity.  It 
  1989. produces a list of the calls that are regarded as subgoals during 
  1990. the course of the program.
  1991.      Subgoals are provided in the line in which they first appear 
  1992. with  a  number,  by  which they are referred  to  in  subsequent 
  1993. occurrences.   The  encapsulation  depth  is  shown  by   varying 
  1994. indentation of the lines.
  1995.  
  1996. The  program  structure analyzer should not be  interrupted  with 
  1997. 'Help',  nor  run in test mode,  as in most cases  cyclical  data 
  1998. structures  will be generated during the course of  the  program. 
  1999. Such data structures also result when,  for example,  the terms X 
  2000. and  f(X)  are  unified.  As you  see,  TOY  Prolog  contains  no 
  2001. 'occurrence  check':  the  terms are unified  and  no  more.  Any 
  2002. attempt to output the resulting expression will certainly lead to 
  2003. an  endless output loop,  leading to a crash of the  interpreter. 
  2004. Such  structures will be generated in the program  analyzer  when 
  2005. recursive predicates are analyzed.
  2006.  
  2007. TOY Prolog ST                  40                           ALPHA
  2008.  
  2009.  
  2010.  
  2011.  
  2012. 5. THE DEMONSTRATION PROGRAMS
  2013.    --------------------------
  2014.  
  2015. 5.1. ALPHA
  2016.      -----
  2017. Source code: '\SOURCE\ALPHA'.
  2018.  
  2019. ALPHA is an example for the development of interactive  programs. 
  2020. After reading in it is called with 'go.'.
  2021.  
  2022. ALPHA  understands three forms of sentence.  The following is  an 
  2023. example dialogue:
  2024.  
  2025.      go.
  2026.      ( ... )
  2027.      John is a man.
  2028.      OK
  2029.      A man is a person.
  2030.      OK
  2031.      Is John a person?
  2032.      Yes.
  2033.      Is Mary a person?
  2034.      I don't know!
  2035.      Bye.
  2036.      ( ... )
  2037.  
  2038. ALPHA  reads  the  sentences  in  with  a  predicate  that  reads 
  2039. individual characters and combines them into words. The resulting 
  2040. list of words is then examined with the aid of grammatical  rules 
  2041. and translated into Prolog instructions.  The entries above,  for 
  2042. example,  will  lead to the following clauses being adopted  into 
  2043. the data bank:
  2044.  
  2045.      man(john).
  2046.      person(X) :- man(X).
  2047.  
  2048. TOY Prolog ST                  41                       TOYSEQUEL
  2049.  
  2050.  
  2051.  
  2052.  
  2053. 5.2. TOYSEQUEL (relational database)
  2054.      ------------------------------
  2055. Source: '\SOURCE\TOYSEQ'
  2056.  
  2057. TOYSEQUEL (© 1983 Kluzniak & Szpakowicz) is a considerably larger 
  2058. example on the use of grammatical rules for the implementation of 
  2059. a command language.  TOYSEQUEL represents a relational  database. 
  2060. An  exact  description of its commands is found  in  "Prolog  for 
  2061. Programmers". Here only the basics can be gone into, in fact with 
  2062. examples.
  2063.  
  2064. Call of TOYSEQUEL:
  2065.      :- toysequel.
  2066.  
  2067. Generating a few relations:
  2068.      create Employee < string name, integer salary, integer
  2069.                          deptno >.
  2070.      create Dept < integer deptno, string manager >.
  2071.      create Board < string name, integer function >.
  2072.  
  2073. Entry of data tuples:
  2074.      into Employee insert <"Smith", 1000, 1>, <"Jones", 1200, 2>,
  2075.                           <"Robinson", 600, 1>.
  2076.      into Dept insert <1, "Murdoch">, <2, "Chamberlain">.
  2077.  
  2078. Queries on relations:
  2079.      relations.
  2080.      Board
  2081.      Dept
  2082.      Employee
  2083.  
  2084.      relation Employee.
  2085.      string name
  2086.      integer salary
  2087.      integer deptno
  2088.  
  2089. Examination of tuples with particular properties:
  2090.      select from Employee tuples <name, salary> where deptno = 1.
  2091.      Smith 1000
  2092.      Robinson 600
  2093.  
  2094. Entry of selected tuples:
  2095.      into Employee insert select from Dept tuples <manager, 1000,
  2096.                deptno>.
  2097.  
  2098. Alteration of tuples:
  2099.      update Employee so that salary = 1200 where
  2100.                name = "Murdoch".
  2101.  
  2102.      from Employee delete tuples where name = "Chamberlain".
  2103.  
  2104.  
  2105. TOY Prolog ST                  42   TOYSEQUEL - Noughts & crosses
  2106.  
  2107.  
  2108. The  program's capabilities go considerably  farther;  there  are 
  2109. various   possibilities   for  comparison  of   any   complicated 
  2110. arithmetic expression;  if a name occurs in several relations, it 
  2111. can be fixed unambiguously by qualifications;  a relation  needed 
  2112. several times in one command can be given 'alias' names, etc.
  2113.  
  2114. Three important commands:
  2115.      dump to FILENAME.
  2116.                saves the relations in the given file.
  2117.  
  2118.      load from FILENAME.
  2119.                loads a file.
  2120.  
  2121.      stop.
  2122.                returns to TOY Prolog.
  2123.  
  2124.  
  2125. 5.3. Noughts and Crosses
  2126.      -------------------
  2127. Source: '\SOURCE\TICTAC.TOE'.
  2128. Intermediate code: 'TICTAC.TOY'.
  2129.  
  2130. Noughts  and Crosses should demonstrate the use of  TOY  Prolog's 
  2131. graphics functions.
  2132.  
  2133. It is called by
  2134.  
  2135.      tictactoe.
  2136.  
  2137. The user plays against the computer (the program is rather  slow, 
  2138. so the computer cannot lose).  A move is carried out by the  user 
  2139. pointing  the  mouse pointer at a free square of  the  board  and 
  2140. clicking  the left button.  If the mouse button is clicked  while 
  2141. the pointer is on the 'STOP' button, the program is ended.
  2142.  
  2143. TOY Prolog ST                  43                 The interpreter
  2144.  
  2145.  
  2146.  
  2147.  
  2148.                            APPENDICES
  2149.                            ==========
  2150.  
  2151. A1. THE CONSTRUCTION OF THE INTERPRETER
  2152.     -----------------------------------
  2153. TOY  Prolog  consists  of two parts:  the  inner  and  the  outer 
  2154. interpreter.  The  inner  interpreter is written in C  and  68000 
  2155. Assembler, the outer in Prolog itself. The advantage of this kind 
  2156. of implementation is that many parts of the interpreter are  much 
  2157. easier   to  formulate  in  Prolog  than  in  other   programming 
  2158. languages.
  2159.      An example of this is the predicate 'repeat'.  In Prolog  it 
  2160. is defined as follows:
  2161.  
  2162.      repeat.
  2163.      repeat :- repeat.
  2164.  
  2165. An  implementation  of  'repeat'  in C  would  require  the  data 
  2166. structures  used  by the inner interpreter to  be  extended;  the 
  2167. resulting cost increase would be considerable.
  2168.  
  2169. The technique used naturally has disadvantages too.  The  biggest 
  2170. is undoubtedly the lower speed.  The entire parser of TOY  Prolog 
  2171. is implemented in the outer interpreter,  and on the basis of the 
  2172. complex  syntax (TOY Prolog is supposed to be largely  compatible 
  2173. with  Prolog-10)  the parser is very  lavish.  One  notices  this 
  2174. particularly painfully when reading in files with 'consult', etc.
  2175.  
  2176. The  program's  low  speed on reading in can be got  round  in  a 
  2177. simple way.  As soon as you have a correct program available, you 
  2178. can  translate it into the syntax of the inner  interpreter.  The 
  2179. speed  with  which  such intermediate code can  be  read  in  far 
  2180. surpasses the reading speed of the outer interpreter.
  2181.  
  2182. The  outer  interpreter consists essentially of  a  program  loop 
  2183. (loop / 0),  which reads in terms with 'read' and evaluates them. 
  2184. This loop can also be called from user programs with 'tag(loop)';
  2185. it  is  interrupted  by  means  of  the  predicate  'stop'.  This 
  2186. possibility is used for example in the editor.
  2187.  
  2188. The  type  and  manner of implementation demand  that  the  outer 
  2189. interpreter is read in after the start of the program.  For  this 
  2190. there   is in TOY Prolog a system file called  'SYSFILE.TOY'.  It 
  2191. contains besides the intermediate code for the outer  interpreter 
  2192. other important data,  in particular the names and arities of the 
  2193. system   functions   and  the  definitions  of   the   predefined 
  2194. predicates.  The construction of the system file is explained  in 
  2195. Appendix 3.
  2196.  
  2197. TOY Prolog ST                  44     Syntax of inner interpreter
  2198.  
  2199.  
  2200.  
  2201.  
  2202. A2. THE SYNTAX OF THE INNER INTERPRETER
  2203.     -----------------------------------
  2204. The syntax description follows,  analogous to the description  of 
  2205. the complete syntax in section 2.
  2206.  
  2207. clause              ::= rule | goal
  2208. rule                ::= f_term : call_list
  2209. goal                ::= : call_list #
  2210. call_list           ::= { call . } []
  2211. call                ::= f_term
  2212.  
  2213. f_term              ::= functor | functor ( arguments )
  2214. functor             ::= name | q_name | [] | !
  2215. arguments           ::= term { , term }
  2216. term                ::= ( term ) | variable | number | f_term |
  2217.                         term . term
  2218. variable            ::= anonymous_variable | numbered_variable
  2219. anonymous_variable  ::= _
  2220. numbered_variable   ::= : number
  2221.  
  2222. number              ::= sign digit { digit }
  2223. name                ::= small_letter { alphanumeric }
  2224. q_name              ::= ' q_character { q_character } '
  2225. q_character         ::= '' | not_'
  2226.                          *** not_' is any character other than '
  2227. alphanumeric        ::= small_letter | capital_letter | digit | _
  2228. sign                ::= + | | -
  2229.                          *** The sign can also be absent.
  2230. *** small_letter, capital_letter, digit : see section 2.
  2231.  
  2232.  
  2233. Comments
  2234. ~~~~~~~~
  2235. (1)  The inner interpreter reads in only rules and goals, where a 
  2236.      syntactical  goal  is  a  headless  rule.   Facts  must   be 
  2237.      represented  as rules in which the call-list is just  [].  A 
  2238.      goal is terminated by the character '#',  which informs  the 
  2239.      interpreter  that it should start on the evaluation  of  the 
  2240.      goal (i.e. on the attempt to satisfy the goal). No report on 
  2241.      the success or failure of the goal is output.
  2242.  
  2243. (2)  If the inner interpreter reads from the 'user' data  stream, 
  2244.      it behaves as if it had read in the goal
  2245.  
  2246.           : ear . [] #
  2247.  
  2248.      This  goal  is the call of the outer  interpreter  and  must 
  2249.      exist as a predicate.  In case another predicate than  'ear' 
  2250.      has  been entered in the system file (see  Appendix  3),  it 
  2251.      works the same way.
  2252.  
  2253.  
  2254. TOY Prolog ST                  45     Syntax of inner interpreter
  2255.  
  2256.  
  2257. (3)  Anonymous variables read in by the inner interpreter  behave 
  2258.      differently from anonymous variables read in from the  outer 
  2259.      interpreter.   The   inner  interpreter   generates   'true' 
  2260.      anonymous  variables,  which  cannot  be  instantiated  with 
  2261.      values.  The  outer  interpreter  generates  instead  single 
  2262.      instances of 'normal' variables.  The difference is normally 
  2263.      insignificant;   one  should  not  rely,  however,  on  e.g. 
  2264.      'numbervars' really instantiating all variables.
  2265.  
  2266. (4)  When reading in 'numbered' variables,  the inner interpreter 
  2267.      generates  a  table  by  means of which  it  sees  how  many 
  2268.      different   variables  a  term  contains.   Thus  the   term 
  2269.      'f( :1, :100)'  requires only two variables,  not  100.  The 
  2270.      number  allotted  to a variable on input has nothing  to  do 
  2271.      with  the  variable-number given by  'display'  or  'write': 
  2272.      'display'  uses  the internal representation  of  variables, 
  2273.      'write' their sequence in the term.
  2274.  
  2275. TOY Prolog ST                  46                     System file
  2276.  
  2277.  
  2278.  
  2279.  
  2280. A3. THE SYSTEM FILE
  2281.     ---------------
  2282. The system file 'SYSFILE.TOY' consists of three parts:
  2283.  
  2284. -    the  names  and  arities of the  fixed  functors  the  inner 
  2285.      interpreter needs for special purposes. They are ';' and ',' 
  2286.      (needed  for  the implementation of the  'cut'),  'tag'  and 
  2287.      'call',  '[]',  '.',  'error'  (for  the  handling  of  call 
  2288.      errors), 'user' (for i/o), the operator types and 'ear' (the 
  2289.      goal that is called by the inner interpreter).
  2290.           The descriptions of these functors must not be altered; 
  2291.      an exception to this is 'ear', which can be altered so as to 
  2292.      let another goal be called by the inner interpreter.
  2293.  
  2294. -    The names and arities of the system functions.  The names of 
  2295.      the  system  functions can be changed  at  will,  but  their 
  2296.      arities must be preserved.  If the name of a system function 
  2297.      is  altered,  the  change  must be carried  through  in  all 
  2298.      programs,   especially  the  outer  interpreter,   otherwise 
  2299.      programs  requiring the function in question will no  longer 
  2300.      run!
  2301.  
  2302. -    The  system  library.  This contains (in the syntax  of  the 
  2303.      inner   interpreter)  the  definitions  of  the   predefined 
  2304.      predicates   and   the  intermediate  code  of   the   outer 
  2305.      interpreter. What we said above about changing names applies 
  2306.      here too;  changing the definitions does not have such  far-
  2307.      reaching results, but it can quite well lead to programs not 
  2308.      running any more, including the auxiliary programs.
  2309.           More  will be said about changes to the user  interface 
  2310.      in Appendix 4.
  2311.  
  2312. The descriptions of the special functors and system functions are 
  2313. used upon initialization of the inner interpreter;  they are read 
  2314. in after AES,  VDI and the memory sector of the interpreter  have 
  2315. been initialized. 
  2316.      The system library is read in directly after  initialization 
  2317. of  the  inner interpreter;  at the end of the file  there  is  a 
  2318. 'seen',  so  that after the reading in the outer  interpreter  is 
  2319. started.
  2320.  
  2321. TOY Prolog ST                  47                  User interface
  2322.  
  2323.  
  2324.  
  2325.  
  2326. A4. THE IMPLEMENTATION OF THE USER INTERFACE
  2327.     ----------------------------------------
  2328. The  syntax  of the inner interpreter is  actually  very  simple, 
  2329. hence  programs  in  this  form  are  understandable  only   with 
  2330. difficulty;  a program on the scale of the outer interpreter  can 
  2331. therefore  not be developed directly in  intermediate  code.  For 
  2332. this  reason  the user interface is written in a  subset  of  the 
  2333. language being implemented. This "half-language" is restricted in 
  2334. the following points compared with the complete syntax:
  2335.  
  2336. -    Operator  notation and the use of grammatical rules are  not 
  2337.      allowed.
  2338.  
  2339. -    List notation is slightly restricted: in a term of the form
  2340.  
  2341.           [ A, B, C ... | X ]
  2342.  
  2343.      X must be a variable.
  2344.  
  2345. -    The  comma  in  a rule and the symbol ':-'  are  treated  as 
  2346.      separating  characters,  not as operators.  ';' must not  be 
  2347.      used in a rule as a separating character, but as a functor.
  2348.  
  2349. The  auxiliary program 'BOOTER.TOY' can translate  this  notation 
  2350. practically 1:1 into intermediate code.
  2351.  
  2352. The   source  code  for  the  user  interface  is  in  the   file 
  2353. 'MONITOR.PRO';  after translation you should remove all  comments 
  2354. fom the resulting intermediate code,  as they take up quite a lot 
  2355. of space.  Here you should be careful, since many predicates that 
  2356. recognise  or generate comments (in the present version they  are 
  2357. 'skip',  'absorbtoken' and 'nextline') use the character '%'; one 
  2358. should  therefore  not simply delete all the lines in  which  '%' 
  2359. occurs.
  2360.  
  2361. We  cannot talk here about the methods used in the design of  the 
  2362. outer interpreter,  and its construction;  a detailed description 
  2363. can be found in "Prolog for Programmers".
  2364.  
  2365. TOY Prolog ST                  48             Future developments
  2366.  
  2367.  
  2368.  
  2369.  
  2370. A5. FUTURE DEVELOPMENTS
  2371.     -------------------
  2372. (1)  The  reporting of subgoals in  test  mode  ("CALL",  "REDO", 
  2373. "EXIT",  "FAIL")  still does not function  correctly.  "FAIL"  is 
  2374. signalled at each fault,  also before a 'backtrack', not only (as 
  2375. would be correct) after final failure of the subgoal.  "EXIT", by 
  2376. contrast, is not signalled at every successfully satisfied goal.
  2377.      It  is doubtful whether these defects will be (can be?)  got 
  2378. over  just  yet.  The "FAIL" error is a nuisance  during  program 
  2379. testing  and  will probably be eradicated soon,  but  the  "EXIT" 
  2380. error  is  sometimes  caused by the optimized  (!)  execution  of 
  2381. recursive predicates and cannot - at least in this situation - be 
  2382. prevented.
  2383.      (TOY  Prolog follows a 'tail recursion optimization'  (TRO), 
  2384. which  means that the 'activation records' of predicates  can  be 
  2385. destroyed  if this saves memory.  The name comes  from  recursive 
  2386. predicates in which the recursive call is the last in its clause; 
  2387. though TRO also applies to other situations, e.g. to the 'cut'.)
  2388.  
  2389. (2)  Integration  of  programs in  other  languages  (C,  Pascal, 
  2390. Assembler).
  2391.      (If I ever get round to it,  have to think of a basis and  a 
  2392. way of proceeding ... )
  2393.  
  2394. [Translator's note:  the other material originally in this appen-
  2395. dix has been redistributed to more convenient places.]
  2396.  
  2397.  
  2398. TOY Prolog ST                  49                   General index
  2399.  
  2400.  
  2401.  
  2402.  
  2403.                           GENERAL INDEX
  2404.                           =============
  2405.  
  2406. (The names  of  predicates,  system  functions etc. are  normally
  2407. followed by their arities; for the predefined operators, the type
  2408. specifier is also given.)
  2409.  
  2410.  
  2411. , /2 (xfy)   10, 18; 3, 4, 6,     @>= /2 (xfx)   12, 18
  2412.    17, 27, 44, 46                  
  2413. , (in user interface)   47        ::- (syntax descr. sym.)   3
  2414. ; /2 (xfy)   10, 18; 3, 6, 17,    | (syntax descr. sym.)   3
  2415.    27, 46                         | (in lists)   4, 5
  2416. ';' (resatisfy)   7               { } (syntax descr. sym.)   3
  2417. ; (in user interface)   47        { } (bracket_term)   4, 5
  2418. :- /1 (fx)   3, 4, 7, 17-18, 26   *** (syntax descr. sym.)  3
  2419. :- /2 (xfx)   3, 7, 17-18, 25      
  2420. :- (in user interface)   47       abolish /2   25
  2421. --> /2 (xfx)   4, 7, 17-18        abort   29
  2422. ! /0 ('cut')   27, 44, 46, 48     'absorbtoken'   47
  2423. ' (with functors)   4, 44         activation record   48
  2424. " (with strings)   4, 19          AES   32, 36, 46
  2425. %   5, 47                         alert /3   36
  2426. [ ] (list notation)   4, 47       ALPHA   40
  2427. [] (empty list)   4, 44, 46       alphanum /1   19
  2428. _ (anonymous variable)   4, 44    alphanumeric   4, 44
  2429. . (in int. code)   44, 46         ancestor   27
  2430. : (in int. code)   44             ancestor /1   27
  2431. # (in int. code)   44             anonymous_variable   44-45
  2432.                                   arg /3   22
  2433. + (arith. op., yfx, fx)  11, 18   arguments   44
  2434. + (sign)   44                     arithmetic expression   11
  2435. - (arith. op., yfx, fx)   6,      ASCII   19-20
  2436.    11, 18                         assert /1   25
  2437. - /1 (with filename)   26         assert /3   24
  2438. - (sign)   4, 6, 44               asserta /1   25
  2439. * (arith. op., yfx) 11, 18        assertz /1   25
  2440. / (arith. op., yfx) 11, 18        ATOM   9
  2441.                                   atom /1   21
  2442. = /2 (xfx)   12, 18                
  2443. == /2 (xfx)   12, 18              backtrace   29
  2444. =:= /2 (xfx)   11, 18             backtrack   48
  2445. =\= /2 (xfx)   12, 18             bagof /3   31
  2446. =< /2 (xfx)   12, 18              bell /0   21
  2447. =.. /2 (xfx)   18, 23             bigletter /1   19
  2448. \== /2 (xfx)   12, 18             BNF   3
  2449. < /2 (xfx)   12, 18               body   3, 6
  2450. > /2 (xfx)   12, 18               BOOTER.TOY   37, 48
  2451. >= /2 (xfx)   12, 18              bracket /1   20
  2452. @=< /2 (xfx)   12, 18             bracket_term   4
  2453. @< /2 (xfx)   12, 18              buffer, input   20
  2454. @> /2 (xfx)   12, 18              bugs   48
  2455.  
  2456. TOY Prolog ST                  50                   General index
  2457.  
  2458.  
  2459. call   4, 44                      end_of_line   5, 6, 19, 20
  2460. CALL   9                          eqvar /2   12
  2461. call /1   27, 46                  'e r r'   17
  2462. CALL:   29, 48                    error /1   8, 46
  2463. call_list   44                    escape /0   21
  2464. CALL_LIST   9                     EXIT:   29, 48
  2465. CALLTREE   39                      
  2466. capital_letter   5                fact   3; (in int. code)   44
  2467. CHAR   9                          fail /0   10
  2468. character_group   5, 6            FAIL:   29, 48
  2469. characters, single   19-21        FILENAME   9
  2470. character string   5, 19          file streams   13-16
  2471. CHAR_LIST   9                     fill functions   35
  2472. check /1   10                     f_term   44
  2473. clause   3, 24-27, 38, 44         F_TERM   9
  2474. clause /2   25                    full_stop   5, 6
  2475. clause /5   24                    function key assignment   16
  2476. clear screen   21                 functor   4, 44; fixed   46
  2477. clock, access to   31             functor /3   22
  2478. Clocksin & Mellish   3            functor_term   4
  2479. cls /0   21                        
  2480. command   4, 6, 7                 get /1 (Prolog-10)   20
  2481. command language   41             get0 /1 (Prolog-10)   20
  2482. comment   5, 6, 47                'go.'   40
  2483. condition   4                     goal   7, 44
  2484. consult /1   26; speed of   43    grammatical_rule   4, 30, 41,
  2485. consultall /1   26; 7                47
  2486. cut   27; see also !              graphic output   32-33
  2487. cyclical data structures   6,     graphics example   42
  2488.    39                             grf_arc /5   33
  2489.                                   grf_bar /4   33
  2490. data bank   24-28                 grf_box /4   33
  2491. database, relational   41-42      grf_circle /3   33
  2492. data streams   13-15              grf_clip /5   32
  2493. date /3   31                      grf_colour /4   32
  2494. debug /0   29                     grf_ellipse /4   33
  2495. debug option   29                 grf_f_colour /1   35
  2496. definition   3                    grf_fill /3   33
  2497. delop /1   18                     grf_f_perim /1   35
  2498. descendant   27                   grf_f_style /1   35
  2499. digit   5                         grf_f_type /1   35
  2500. digit /1   19                     grf_f_udpat /1   35
  2501. directive   4, 6                  grf_l_colour /1   33
  2502. directory access   14-15          grf_l_ends /2   34
  2503. disk_dir /1   14                  grf_l_type /1   33
  2504. disk error   15                   grf_l_udstyle /1   33
  2505. disk_search /2   15               grf_l_width /1   34
  2506. disk_search /4   14-15            grf_m_colour /1   34
  2507. display /1   17, 45               grf_m_height /1   34
  2508.                                   grf_mode /0   32
  2509. ear /0   7, 8, 44, 46             grf_mse_form /1   35
  2510. echo /0   16                      grf_mse_form /5   35-36
  2511. editor   38                       grf_mse_hide /0   35
  2512. 'end'   26, 38                    grf_mse_show /1   35
  2513.  
  2514. TOY Prolog ST                  51                   General Index
  2515.  
  2516.  
  2517. grf_mse_state /3   36             markers   32, 34
  2518. grf_m_type /1   34                member /1   31
  2519. grf_pie /5   33                   memory occupancy   31
  2520. grf_pline /1   32                 'midi'   13
  2521. grf_pmarker /1   32               mod (arith. op., xfx)   11, 18
  2522. grf_poly /1   32                  'modem'   13
  2523. grf_rbox /4   33                  MONITOR.PRO   47
  2524. grf_rfbox /4   33                 mouse control   35-36
  2525. grf_t_align /2   34                
  2526. grf_t_colour /1   34              name   44
  2527. grf_t_effects /1   34             NAME   9
  2528. grf_text /3   33                  name /2 (Prolog-10)   22
  2529. grf_t_height /1   34              'nextline'   47
  2530. grf_t_point /1   34               nl /0   21
  2531. grf_t_rotation /1   34            nodebug /0   29
  2532. grf_wrmode /1   32                noecho /0   16
  2533.                                   nonexistent /0   29
  2534. halt /1   28                      nononexistent /0   30
  2535. head   3                          non_operator   4
  2536. Help key   29, 39                 non_terminal symbol   3, 4, 30
  2537.                                   nonvarint /1   21
  2538. inner interpreter   7, 28, 43-    nospy /2   30
  2539.    47; syntax of  31, 37, 43-47   not /1 (fy)   10, 18
  2540. integer   4                       noughts and crosses   42
  2541. INTEGER   9                       number   44
  2542. integer /1   21                   numbered_variable   44-45
  2543. integer, biggest   22             numbervars /1   31
  2544. integers, arithmetic of   10      'numbervars'   45
  2545. intermediate code  7, 43, 46-47   NUM_LIST   9
  2546. interpreter, see inner i.,         
  2547.    outer i.                       occurrence check   6, 39
  2548. interpreter, construction of      once /1   10
  2549.    43                             op /3   17-18
  2550. interrupt   29                    operator   4-6, 17-18
  2551. interrupt /0   29                 operator, mixed   5
  2552. INTR:   29                        operator notation   47
  2553. is /2 (xfx)   11, 18              operator types   46
  2554. isclosedlist /1   31              ordchr /2   19
  2555. iseoln /1   19                    outer interpreter  7, 28, 43-47
  2556.                                    
  2557. 'keybd'   13, 16                  parser   43
  2558. Kluzniak & Szpakowicz   3         phrase /2   30
  2559.                                   pname /2   22
  2560. lastch /1   20                    pnamei /2   22
  2561. last_char (input buffer)  20-21   pointer (in data bank)   27
  2562. length /2   30; 23                precedence   4, 17-18
  2563. less /2   11                      predefined /2   25
  2564. letter /1   19                    predefined data stream   13
  2565. line functions   32, 33-34        predefined operators   9
  2566. list   4, 7, 47; functions        predefined predicates   8, 46
  2567.    30-31                          'printer'   13
  2568. listing /0   26                   proc /1   26
  2569. listing /1   26                   prod /4   10-11
  2570. loop /0   7, 43
  2571.  
  2572. TOY Prolog ST                  52                   General index
  2573.  
  2574.  
  2575. program, control of course of     syntax   3-6; of inner inter-     
  2576.    27-29                             preter   43-47
  2577. program structure analyser   39   SYSFILE.TOY, see system file
  2578. Prolog-10   3, 5, 8, 19, 20, 43   sysload /1   28; creating files
  2579. protect /0   24                      for   31
  2580. protect /2   24                   system error   8
  2581. put /1 (Prolog-10)   20           system file   46; 8, 36, 43
  2582.                                   system functions   8, 25, 46;
  2583. q_name   4, 44                       names of   36
  2584. query   4, 6, 7                   system library   46
  2585.                                    
  2586. rch /0   20                       tag /1   27, 46
  2587. rdch /1   21                      tagcut /1   27
  2588. rdchsk /1   21                    tagexit /1   27-28
  2589. read /1   17, 43                  tagfail /1   27-28
  2590. reconsult /1   26                 tail recursion optimization  48
  2591. recursion   48                    tell /1   14
  2592. redefine /0   25                  telling /1   14
  2593. REDO:   29, 48                    term   4, 44
  2594. repeat /0   27, 43                TERM   9
  2595. retract /1   25                   terminal_symbol   4
  2596. retract /3   24                   test mode   29-30, 39, 48
  2597. rule   3, 44                      text functions   33, 34
  2598. rule_element   4                  time /3   31
  2599.                                   told /0   14
  2600. see /1   14                       TOYSEQUEL   41-42
  2601. seeing /1   14                    transl /2   37
  2602. seen /0   14; 28, 46              translate /2   31
  2603. set_date /3   31                  true /0   10
  2604. set_fstring /2   16               txt_mode /0   32
  2605. set_time /3   31                  type (of operator)   4-6, 17-18
  2606. ShiftAltHelp   29                 type (of term)   21
  2607. side_effects /1   10               
  2608. sign   44                         unification   9; algorithm   6
  2609. single-step mode   29             unprotect /0   24
  2610. skip /1 (Prolog-10)   20, 47      unprotect /2   24
  2611. skipbl /0   20                    'user' data stream   7, 13-14,
  2612. slash    27                          16, 44, 46
  2613. smalletter /1   19                user interface   7, 36, 37;
  2614. small_letter   5                     implementation of   47
  2615. solochar /1   20                   
  2616. solo_char   5                     VAR   9
  2617. space   5, 6                      var /1   21
  2618. spied /2   30                     variable   4, 44
  2619. spy /2   30                       VARINT   9
  2620. status /0   31                    VDI   32, 46
  2621. step   29                         'V'(N)   17, 31
  2622. stop /0   7, 28                    
  2623. string, see character string      wch /1   21
  2624. subgoals   39, 48                 word   4
  2625. sum /3   10                       write /1   17, 45
  2626. symbol_char   5                   writeq /1   17
  2627. symch /1   20                      
  2628.  
  2629. TOY Prolog ST                  53          Index to GEM functions
  2630.  
  2631.  
  2632.  
  2633.  
  2634.                      INDEX TO GEM FUNCTIONS
  2635.                      ======================
  2636.  
  2637.           Standard name       Prolog name         Page
  2638.  
  2639.           Dgetpath, Dsetpath  disk_dir /1         14
  2640.           form_alert          alert /3            36
  2641.           Fsfirst             disk_search /4      14-15
  2642.           Fsnext              disk_search /2      15
  2643.           graf_mkstate        grf_mse_state /3    36
  2644.           graf_mouse          grf_mse_form /1     35
  2645.           (set mouse f.d.b.)  grf_mse_form /5     35-36
  2646.           v_arc               grf_arc /5          33
  2647.           v_bar               grf_bar /4          33
  2648.           v_circle            grf_circle /3       33
  2649.           v_contourfill       grf_fill /3         33
  2650.           v_ellipse           grf_ellipse /4      33
  2651.           v_enter_cur         txt_mode /0         32
  2652.           v_exit_cur          grf_mode /0         32
  2653.           v_fillarea          grf_poly /1         32
  2654.           v_gtext             grf_text /3         33
  2655.           v_hide_c            grf_mse_hide /0     35
  2656.           v_pieslice          grf_pie /5          33
  2657.           v_pline             grf_pline /1        32
  2658.           v_pmarker           grf_pmarker /1      32
  2659.           v_rbox              grf_rbox /4         33
  2660.           v_rfbox             grf_rfbox /4        33
  2661.           vr_recfl            grf_box /4          33
  2662.           vs_clip             grf_clip /5         32
  2663.           vs_color            grf_colour /4       32
  2664.           vsf_color           grf_f_colour /1     35
  2665.           vsf_interior        grf_f_type /1       35
  2666.           vsf_perimeter       grf_f_perim /1      35
  2667.           vsf_style           grf_f_style /1      35
  2668.           vsf_udpat           grf_f_udpat /1      35
  2669.           v_show_c            grf_mse_show /1     35
  2670.           vsl_color           grf_l_colour /1     33
  2671.           vsl_ends            grf_l_ends /2       34
  2672.           vsl_type            grf_l_type /1       33
  2673.           vsl_udsty           grf_l_udstyle /1    33
  2674.           vsl_width           grf_l_width /1      34
  2675.           vsm_color           grf_m_colour /1     34
  2676.           vsm_height          grf_m_height /1     34
  2677.           vsm_type            grf_m_type /1       34
  2678.           vst_alignment       grf_t_align /2      34
  2679.           vst_color           grf_t_colour /1     34
  2680.           vst_effects         grf_t_effects /1    34
  2681.           vst_height          grf_t_height /1     34
  2682.           vst_point           grf_t_point /1      34
  2683.           vst_rotation        grf_t_rotation /1   34
  2684.           vswr_mode           grf_wrmode /1       32
  2685.  
  2686.